Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

excel vba introduction

Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Excel VBA Introduction - Count Rows to set a For Range

Excel VBA Introduction - Count Rows to set a For Range

ResolvedVersion 2010

Ben has attended:
Excel VBA Introduction course

Excel VBA Introduction - Count Rows to set a For Range

Have been trying to replicate some of the code from the introduction course.

Am trying to use the Count function we discussed with Jens, in order to identify how many iterations to go through:

For I = 1 to (number of rows in the selected data)


I am using

Range("f3").CurrentRegion.Select


For i = 1 To (Selection.Rows.Count.Value)

Jens' way seemed very simple, but I can't find anything as simple on Google.

thanks

RE: Excel VBA Introduction - Count Rows to set a For Range

Hi Ben,

Thank you for your question. It works best if you declare two simple variables.

The code will look as follows:

Dim rowcounter as long
Dim i as long

rowcounter = range("f3").currentregion.rows.count

For i = 1 to rowcounter

(Place the rest of your code here to state what needs to happen with the records)

Next i

I hope this helps!

Kind regards
Marius Barnard
STL Trainer

 

Training courses

Training information:

Welcome. Please choose your application (eg. Excel) and then post your question.

Our Microsoft Qualified trainers will then respond within 24 hours (working days).

Frequently Asked Questions
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.

Excel tip:

Multiple Lines of Text in a Cell

As an alternative to the Text Wrapping facility, type a word or two, press Alt+Enter to get a new line, type more text, and continue the process for as many lines as you need. Enter as normal when you have finished.

The line break is not affected by changing the column width, as text wrapping. To remove this you must edit the cell and remove the invisible character and replace with a normal space.

View all Excel hints and tips

Connect with us:

0207 987 3777

Call for assistance

Request Callback

We will call you back

Server loaded in 0.1 secs.