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

#### motilulla

##### Well-known Member
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

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number

#### Fluff

##### MrExcel MVP, Moderator
You can use this formula
=COUNTIF(INDEX(D\$1:D\$100,E\$1):D\$100,G6)

#### Fluff

##### MrExcel MVP, Moderator
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``````

#### motilulla

##### Well-known Member
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>

</SPAN></SPAN>

Kind Regards
</SPAN></SPAN>
Moti
</SPAN></SPAN>

#### Fluff

##### MrExcel MVP, Moderator
Glad to help & thanks for the feedback

Replies
9
Views
319
Replies
21
Views
1K
Replies
1
Views
63
Replies
6
Views
194
Replies
1
Views
71

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

1,163,559
Messages
5,832,462
Members
430,136
Latest member
Asir Jefferson

### 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.

### Which adblocker are you using?

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

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