Loop Question

Braunschweiger

Board Regular
Joined
Feb 19, 2014
Messages
104
I'm tying to make sure I understand the code below which is part of one or my loops.

QUESTION: Where you see End(3) -- what does the "3" stand for?

VBA Code:
For i = 9 To Range("B" & Rows.Count).End(3).Row

  1. "i" could be anything...correct? It's just common to use "i".
  2. 9 simply starts the loop at the 9th row...correct?
  3. "B" self explanatory...points to the second column or, column "B"
  4. "Rows.Count" counts the rows starting at the 9th row in column "B"
  5. Regarding "Rows.Count" - what other code could be substituted for "Count"...what else could "Rows.?????" be used for?
  6. "End" - why do we need to include "End"?
  7. And finally, what does the "3" stand for?
Thanks in advance, wanting to make sure I understand a loop I'm using before I alter it and use it in another place.
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Parts 1,2 & 3 are correct.
4) Rows.count counts the total number of rows in the sheet (normally 1048576)
5) Not sure I understand
7) the 3 stands for xlUp
6) End(3) tells the code to go upwards until it finds either a blank cell, or a non blank cell (depending on various conditions) Its the same as using Ctrl up arrow on a sheet.
 
Upvote 0
Solution
Parts 1,2 & 3 are correct.
4) Rows.count counts the total number of rows in the sheet (normally 1048576)
5) Not sure I understand
7) the 3 stands for xlUp
6) End(3) tells the code to go upwards until it finds either a blank cell, or a non blank cell (depending on various conditions) Its the same as using Ctrl up arrow on a sheet.

Regarding 7 & 6...I think I understand...the 3 or x1Up started at the first row at the end of a column with data in it so...it's kind of counting backwards right? Starting from the last cell in a row rather than the 1st cell in a row. Am I following?

Number 5 is not big deal...I was just wondering if there's other commands you could attach to the Row.Count...is there anything that could replace "Count", Row.Add or Row.x1Up...just curious...no biggie if this is kind of a dumb questions...feel free to skip it.
 
Upvote 0
This
VBA Code:
Range("B" & Rows.Count).End(3).Row
Is saying move up from the last cell in col B until it finds a cell that is not empty & then returns the row number.
 
Upvote 0

Forum statistics

Threads
1,214,405
Messages
6,119,323
Members
448,887
Latest member
AirOliver

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