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!
 
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
Hello this works for me, thanks!! Could you also assist me on this:

in regards to the data in column C i would like to create numbering to it:

my code below, however same thing happen if there is only one row. Much thanks :)

Range("B9").Select

ActiveCell.FormulaR1C1 = "=IF(RC[1]<>"""",COUNTA(R9C3:RC3)-COUNTBLANK(R9C3:RC3),"""")"

Range("B9").AutoFill Range("B9:B" & Range("C" & Rows.Count).End(xlUp).Row)
 
Upvote 0

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Hello this works for me, thanks!! Could you also assist me on this:

in regards to the data in column C i would like to create numbering to it:

my code below, however same thing happen if there is only one row. Much thanks :)

Range("B9").Select

ActiveCell.FormulaR1C1 = "=IF(RC[1]<>"""",COUNTA(R9C3:RC3)-COUNTBLANK(R9C3:RC3),"""")"

Range("B9").AutoFill Range("B9:B" & Range("C" & Rows.Count).End(xlUp).Row)
Are you sure the formula does what you want?
Post some sample data of how to number column B.
 
Upvote 0
Hello @footoo , thanks for yr help. As picture attached (top - raw data) (bottom - outcome) - hope its clearer now

- remove duplicates
- numbering

Concern: Variable rows, sometimes there will be only one row
 

Attachments

  • Oicture.png
    Oicture.png
    41.5 KB · Views: 4
Upvote 0
Maybe this :
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 & ")")
[B9] = 1
Range(r).Offset(1, -1).Formula = "=IF(C10="""","""",IF(C9="""",1,B9+1))"
End Sub
Or this :
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 & ")")
Range(r)Offset(0, -1).Formula = "=IF(C9<>"""",counta($C$9:$C9),""""))"
End Sub
 
Last edited:
Upvote 0
Correction to second macro :
VBA Code:
Range(r)Offset(0, -1).Formula = "=IF(C9<>"""",counta($C$9:$C9),"""")"
 
Last edited:
Upvote 0
Hihi, why when i change to this in macro it will highlight in red? The first macro came back with 1 and then 1 as attached
Correction to second macro :
VBA Code:
Range(r)Offset(0, -1).Formula = "=IF(C9<>"""",counta($C$9:$C9),"""")"
 

Attachments

  • Oicture.png
    Oicture.png
    13.6 KB · Views: 1
Upvote 0
VBA Code:
Range(r).Offset(0, -1).Formula = "=IF(C9<>"""",counta($C$9:$C9),"""")"
 
Upvote 0

Forum statistics

Threads
1,215,066
Messages
6,122,948
Members
449,095
Latest member
nmaske

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