vba how to apply for.....next

montecarlo2012

Well-known Member
Joined
Jan 26, 2011
Messages
986
Office Version
  1. 2010
Platform
  1. Windows
Hi.
working on:
VBA Code:
 [B5].Value2 = Application.Count(Range("B2", [B2].End(xlToRight)))
    [B21].Value2 = Application.Count(Range("B18", [B18].End(xlToRight)))
    [B37].Value2 = Application.Count(Range("B34", [B34].End(xlToRight)))
    [B53].Value2 = Application.Count(Range("B50", [B50].End(xlToRight)))
    [B69].Value2 = Application.Count(Range("B66", [B66].End(xlToRight)))
    [B85].Value2 = Application.Count(Range("B82", [B82].End(xlToRight)))
Please some cooperation here.
How to apply for next loop in this case.
Thanks for reading this.
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Hi, for starters :​
VBA Code:
         Dim V, S$()
    For Each V In Split("B5:B2 B21:B18 B37:B34 B53:B50 B69:B66 B85:B82")
        S = Split(V, ":")
        Range(S(0)).Value2 = Application.Count(Range(S(1), Range(S(1)).End(xlToRight)))
    Next
 
Upvote 0
Solution
A variation :​
VBA Code:
    Dim V, R&
        V = [{5,2;21,18;37,34;53,50;69,66;85,82}]
    For R = 1 To UBound(V)
        Cells(V(R, 1), 2).Value2 = Application.Count(Range(Cells(V(R, 2), 2), Cells(V(R, 2), 2).End(xlToRight)))
    Next
 
Upvote 0
Last but not least, an Array variation :​
VBA Code:
         Dim V
    For Each V In Array([{5,2}], [{21,18}], [{37,34}], [{53,50}], [{69,66}], [{85,82}])
        Cells(V(1), 2).Value2 = Application.Count(Range(Cells(V(2), 2), Cells(V(2), 2).End(xlToRight)))
    Next
 
Upvote 0

Forum statistics

Threads
1,224,747
Messages
6,180,712
Members
452,995
Latest member
isldboy

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