In the VBA formula, need to get starting row number from the cell value

motilulla

Well-known Member
Joined
Feb 13, 2008
Messages
2,422
Office Version
  1. 2010
Hello,</SPAN></SPAN>

In the cell H6 I have a formula =COUNTIF(D$6:D$100,G6) which start counting unique data of column D from the starting row 6, I need help how can I change starting row number 6 to x row "in the formula above which I am running via VBA" does it is possible VBA formula can pick starting row number from the cell E1 and become =COUNTIF(D$15:D$100,G6)
</SPAN></SPAN>

Code:
Sub CountUniques()
    Range("H6:H15").Formula = "=COUNTIF(D$6:D$100,G6)"
    Range("H7:H15") = Range("H7:H15").Value
End Sub


Book1
DEFGH
115
2
3
4
5DataUniques NumbersCounts
6116
7120
8130
9444
10554
11664
12772
13981
141092
1510103
1610
179
188
197
206
216
226
235
245
255
264
274
284
291
301
311
Sheet1


Thank you all
</SPAN></SPAN>

Excel 2000
</SPAN></SPAN>
Regards,
</SPAN>
Moti
</SPAN></SPAN>
 
Last edited:

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
You can use this formula
=COUNTIF(INDEX(D$1:D$100,E$1):D$100,G6)
 
Upvote 0
Or with VBA
Code:
Sub CountUniques()
    With Range("H6:H15")
        .Value = Evaluate("if({1},COUNTIF(INDEX(D$1:D$100,E$1):D$100," & .Offset(, -1).Address & "))")
    End With
End Sub
 
Upvote 0
Solution
You can use this formula
=COUNTIF(INDEX(D$1:D$100,E$1):D$100,G6)
Or with VBA
Code:
Sub CountUniques()
    With Range("H6:H15")
        .Value = Evaluate("if({1},COUNTIF(INDEX(D$1:D$100,E$1):D$100," & .Offset(, -1).Address & "))")
    End With
End Sub
Fluff, the VBA formula is spot on, and so kind of you for the additional formula :)</SPAN></SPAN>

Very much appreciated your prompt reply and kind help
</SPAN></SPAN>

Kind Regards
</SPAN></SPAN>
Moti :-D
</SPAN></SPAN>
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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