Can You Get Row/Col Info Using FOR EACH Loop?

CaliKidd

Board Regular
Joined
Feb 16, 2011
Messages
173
I read on another site that one way you can speed up code is as follows:
Rich (BB code):
mProduct = 1
For i = 5 to 10
mProduct = mProduct * Cells(3,i)
 
Next
 
Use 'For Each' rather than 'indexed For': We can avoid using Indexed For when looping through collections. For example, take the code just before this tip. It can be modified to:
For Each myCell in Range("C5:C10")
mProduct = mProduct * myCell.Value
 
Next
In the first example, i is the column number, but how can you get the cell address or column when using the For Each loop?
 

Some videos you may like

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)

CaliKidd

Board Regular
Joined
Feb 16, 2011
Messages
173
OK, I figured it out. I would use myCell.Row or myCell.Column to get the corresponding valued needed.

CLOSED. :)
 

Watch MrExcel Video

Forum statistics

Threads
1,109,446
Messages
5,528,802
Members
409,836
Latest member
karnasrinivas

This Week's Hot Topics

  • Change military grades into rank
    Afternoon all Need help with formula that will change military rank (i.e. 1, 2, 3 into Amn, A1C, SrA). Running IF formula that does not work...
  • VBA COUNTIF SOLUTION
    Hi The following are the errors spread across the several columns from E to Q ie. 13 columns across several sheets with more than 500 rows per...
  • INSERT ROW WITH SPECIFIS TEXT IN A COLUMN
    Hi All! How can identify that that the row to be inserted has to be inserted before 1st row with specific text in column F. If I record the...
  • Auto-Create a monthly Sign in sheet for preschool students
    The image below is what each page looks like. Above is space for the "Child Name" "Month" "Class" School days are obviously Monday-Friday but...
  • VBA vlookup multiple results
    Hi folks, Hopefully someone out there can help. I have a list to vlookup which works (ish). the lookup only picks up the first instance of the...
  • Extract values for earliest/latest times
    I am trying to put together a formula to get the earliest start time, the latest end time from column A for each person in Column B-F without the...
Top