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

motilulla

Well-known Member
Joined
Feb 13, 2008
Messages
2,360
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

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
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 :biggrin:
</SPAN></SPAN>
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,751
Members
448,989
Latest member
mariah3

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