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

motilulla

Well-known Member
Joined
Feb 13, 2008
Messages
2,076
Office Version
  1. 2003 or older
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
Joined
Jun 12, 2014
Messages
73,028
Office Version
  1. 365
Platform
  1. Windows
You can use this formula
=COUNTIF(INDEX(D$1:D$100,E$1):D$100,G6)
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
73,028
Office Version
  1. 365
Platform
  1. Windows
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
 
Solution

motilulla

Well-known Member
Joined
Feb 13, 2008
Messages
2,076
Office Version
  1. 2003 or older
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>
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
73,028
Office Version
  1. 365
Platform
  1. Windows
Glad to help & thanks for the feedback
 
Master Excel Bundle

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.

Forum statistics

Threads
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.
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
Top