Excel VBA Obtain the Column and Row of current element in For Each loop

0 votes

Since I'm still learning how to use VBA Excel Macros, I'm sure I misread something.

I'm attempting to get the range of the element "rng" that is looping in a for each loop, like "A1", "A2", etc., but I'm just receiving the cell value. VBA, I supposed. Interaction. However, MsgBox prompt:=rng does not also return the range value of the current cell.

Although I streamlined the code, the goal is to preserve the locations of cells ("A1," "A2," etc.) that meet a criteria in an array for later processing.

In a For Each loop, how do I get the column and row indexes of the rng?

Sub test() Dim rng As Range
For Each rng In Range("A1:A10")
    rng.Value = rng.Value + 10
    VBA.Interaction.MsgBox prompt:=rng ' this gives me 10, 10,... instead of "A1", "A2"....
Next rng

End Sub
Feb 14 in Others by narikkadan
• 63,040 points
176 views

1 answer to this question.

0 votes

Try this:

MsgBox rng.Address(RowAbsolute:=False, ColumnAbsolute:=False )
answered Feb 14 by Kithuzzz
• 38,010 points

Related Questions In Others

0 votes
1 answer

How to increment the Range of a For Each loop - Excel VBA

Your formula seems to sum 1 single ...READ MORE

answered Jan 7 in Others by narikkadan
• 63,040 points
696 views
0 votes
1 answer

In excel how do I reference the current row but a specific column?

Put a $ symbol in front of ...READ MORE

answered Oct 15, 2022 in Others by narikkadan
• 63,040 points
564 views
0 votes
1 answer

Excel - How can I get the average of cells where the value in one column is X and the value in another column is Y?

Use AVERAGEIFS ... =AVERAGEIFS(C2:C13,A2:A13,"Yellow Typ ...READ MORE

answered Nov 11, 2022 in Others by narikkadan
• 63,040 points
585 views
0 votes
1 answer
0 votes
1 answer

How to find all internal ranges in a specified range

It is simple to compare once you ...READ MORE

answered Mar 27 in Others by narikkadan
• 63,040 points
81 views
0 votes
1 answer

Retrieve epay.info Balance with VBA and Excel

This code should log you in, provided ...READ MORE

answered Sep 5, 2018 in Blockchain by digger
• 26,740 points
631 views
0 votes
1 answer

How to load file to Excel Power query from SFTP site

Currently, I don't think there is a ...READ MORE

answered Dec 3, 2018 in Power BI by Upasana
• 8,620 points
2,718 views
0 votes
1 answer

Using VBA Excel to create a gramatically correct list

The Excel AND function is a logical ...READ MORE

answered Feb 9, 2022 in Others by gaurav
• 22,980 points
184 views
0 votes
1 answer

Excel VBA- How to loop through specific sheets in a workbook and format the same ranges in each sheet

Range(...) instructs VBA to always use the ...READ MORE

answered Mar 21 in Others by Kithuzzz
• 38,010 points
183 views
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP