Autofill destination VBA

wenhwei17

New Member
Joined
Jan 8, 2021
Messages
15
Office Version
  1. 2010
Platform
  1. Windows
Hello all!

i have this formula for autofill formula typed in cell V9

Selection.autofill destination:=range(“v9:v” & range (“u” & rows.count).end(x1up).row)

however if there is only one row then it will have error. Need help on this thanks!
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
I think You Have Typo at Xlup not X1up ( it is lower L not 1) And don't need select it
VBA Code:
Range("V9").autofill destination:=range(“v9:v” & range (“u” & rows.count).end(xlup).row)
 
Upvote 0
hello! I have changed it but it still says autofill method of range class failed hmm
I think You Have Typo at Xlup not X1up ( it is lower L not 1) And don't need select it
VBA Code:
Range("V9").autofill destination:=range(“v9:v” & range (“u” & rows.count).end(xlup).row)
)
 
Upvote 0
Are you change ranges. your destination range must include also source range.
Also Change With "
Try This:
VBA Code:
Range("V9").AutoFill Destination:=Range("V9:V" & Range("U" & Rows.Count).End(xlUp).Row)
 
Upvote 0
Are you change ranges. your destination range must include also source range.
Also Change With "
Try This:
VBA Code:
Range("V9").AutoFill Destination:=Range("V9:V" & Range("U" & Rows.Count).End(xlUp).Row)
Hello thanks for your reply. However i dont quite understand. Maybe i show u the full vba:

Range("C9").Select

Range(Selection, Selection.End(xlDown)).Select

Selection.copy

Range("U9").Select

Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

:=False, Transpose:=False

Range("V9").Select

Application.CutCopyMode = False

ActiveCell.FormulaR1C1 = "=IF(RC[-1]=R[-1]C[-1],"""",RC[-1])"

Range("V9").Select



Selection.AutoFill Destination:=Range("V9:V" & Range("U" & Rows.Count).End(xlUp).Row)

Range(Selection, Selection.End(xlDown)).Select



Selection.copy

Range("C9").Select

Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

:=False, Transpose:=False

Columns("U:V").Select

Application.CutCopyMode = False

Selection.ClearContents
 
Upvote 0
Try this:
VBA Code:
Sub DataValid1()
Dim Lr As Long
Lr = Range("C" & Rows.Count).End(xlUp).Row
Range("C9:C" & Lr).Copy
Range("U9").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
'Application.CutCopyMode = False
Range("V9").FormulaR1C1 = "=IF(RC[-1]=R[-1]C[-1],"""",RC[-1])"
Range("V9").AutoFill Destination:=Range("V9:V" & Range("U" & Rows.Count).End(xlUp).Row)
Range("V9:V" & Lr).Copy
Range("C9").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Columns("U:V").ClearContents
'Application.CutCopyMode = False
End Sub
 
Upvote 0
Try this:
VBA Code:
Sub DataValid1()
Dim Lr As Long
Lr = Range("C" & Rows.Count).End(xlUp).Row
Range("C9:C" & Lr).Copy
Range("U9").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
'Application.CutCopyMode = False
Range("V9").FormulaR1C1 = "=IF(RC[-1]=R[-1]C[-1],"""",RC[-1])"
Range("V9").AutoFill Destination:=Range("V9:V" & Range("U" & Rows.Count).End(xlUp).Row)
Range("V9:V" & Lr).Copy
Range("C9").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Columns("U:V").ClearContents
'Application.CutCopyMode = False
End Sub
I still got stuck here

Sub DataValid1()
Dim Lr As Long
Lr = Range("C" & Rows.Count).End(xlUp).Row
Range("C9:C" & Lr).Copy
Range("U9").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
'Application.CutCopyMode = False
Range("V9").FormulaR1C1 = "=IF(RC[-1]=R[-1]C[-1],"""",RC[-1])"
Range("V9").AutoFill Destination:=Range("V9:V" & Range("U" & Rows.Count).End(xlUp).Row)
Range("V9:V" & Lr).Copy
Range("C9").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Columns("U:V").ClearContents
'Application.CutCopyMode = False
End Sub
 
Upvote 0
@wenhwei17 you can just apply the formula directly to the range without autofilling.
VBA Code:
    With Range("V9:V" & Range("U" & Rows.Count).End(xlUp).Row)
        .FormulaR1C1 = "=IF(RC[-1]=R[-1]C[-1],"""",RC[-1])"
        .Value = .Value
    End With
 
Upvote 0
Or change column C directly (without using columns U:V) :
VBA Code:
Sub DataValid1()
Dim r$: r = Range("C9:C" & Cells(Rows.Count, 3).End(3).Row).Address
Range(r) = Evaluate("IF(" & r & "=" & Range(r).Offset(-1).Address & ",""""," & r & ")")
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,215,059
Messages
6,122,918
Members
449,093
Latest member
dbomb1414

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top