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

motilulla

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

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
75,967
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
75,967
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,104
Office Version
  1. 2010
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
75,967
Office Version
  1. 365
Platform
  1. Windows
Glad to help & thanks for the feedback
 

Forum statistics

Threads
1,171,192
Messages
5,874,266
Members
433,042
Latest member
mcm2022

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