R/T Error 1004

J

Jim May

Code is Bombing 4 lines from bottom;
How can I alter to fix?

Sub FillInBlanks()
Dim Rng1 As Range, Rng2 As Range
Dim RngArea As Range
If Selection.Columns.Count > 1 Then
MsgBox "You can Only Select 1 Column at a time"
Exit Sub
End If
Set Rng1 = Selection
Set Rng2 = Rng1.SpecialCells(xlCellTypeBlanks)
Rng2.FormulaR1C1 = "=R[-1]C"
With Rng2
.Copy
.PasteSpecial xlPasteValues ' R/T 1004 - CANNOT BE USED ON MULTIPLE
SELECTIONS
End With
Application.CutCopyMode = False
End Sub
 
N

Norman Jones

Hi Jim,

Try:

'=============>>
Public Sub FillInBlanks()
Dim Rng1 As Range, Rng2 As Range
Dim RngArea As Range

If Selection.Columns.Count > 1 Then
MsgBox "You can Only Select 1 Column at a time"
Exit Sub
End If

Set Rng1 = Selection

On Error Resume Next 'In case no blanks found!
Set Rng2 = Rng1.SpecialCells(xlCellTypeBlanks)
On Error GoTo 0

If Not Rng2 Is Nothing Then
Rng2.FormulaR1C1 = "=R[-1]C"
With Rng1
.Value = .Value
End With
End If
End Sub
'<<=============
 
J

Jim May

Norman,
Anytime when returning to my PC after posting a Question AND I see
"Norman Jones" - I know I'm gonna get a good reply +++ learn something
GOOD - Your
Suggested code is perfect - Yeah it's the original Values Rng1 that need
Converting to Values, not having to refer to the Rng2. Thanks Again;
Jim May

Hi Jim,

Try:

'=============>>
Public Sub FillInBlanks()
Dim Rng1 As Range, Rng2 As Range
Dim RngArea As Range

If Selection.Columns.Count > 1 Then
MsgBox "You can Only Select 1 Column at a time"
Exit Sub
End If

Set Rng1 = Selection

On Error Resume Next 'In case no blanks found!
Set Rng2 = Rng1.SpecialCells(xlCellTypeBlanks)
On Error GoTo 0

If Not Rng2 Is Nothing Then
Rng2.FormulaR1C1 = "=R[-1]C"
With Rng1
.Value = .Value
End With
End If
End Sub
'<<=============


---
Regards,
Norman



Code is Bombing 4 lines from bottom;
How can I alter to fix?

Sub FillInBlanks()
Dim Rng1 As Range, Rng2 As Range
Dim RngArea As Range
If Selection.Columns.Count > 1 Then
MsgBox "You can Only Select 1 Column at a time"
Exit Sub
End If
Set Rng1 = Selection
Set Rng2 = Rng1.SpecialCells(xlCellTypeBlanks)
Rng2.FormulaR1C1 = "=R[-1]C"
With Rng2
.Copy
.PasteSpecial xlPasteValues ' R/T 1004 - CANNOT BE USED ON MULTIPLE
SELECTIONS
End With
Application.CutCopyMode = False
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top