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, 2023 in Others by narikkadan
• 63,600 points
1,326 views

1 answer to this question.

0 votes

Try this:

MsgBox rng.Address(RowAbsolute:=False, ColumnAbsolute:=False )
answered Feb 14, 2023 by Kithuzzz
• 38,000 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, 2023 in Others by narikkadan
• 63,600 points
2,772 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,600 points
1,967 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,600 points
1,420 views
0 votes
1 answer

VBA code help - Add a line for each missing date with the start and end date defined in a cell

Try this: Sub FillDates() Dim ...READ MORE

answered Jan 24, 2023 in Others by narikkadan
• 63,600 points
1,016 views
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, 2023 in Others by narikkadan
• 63,600 points
663 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
1,260 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
3,698 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
• 23,260 points
979 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, 2023 in Others by Kithuzzz
• 38,000 points
1,799 views
0 votes
1 answer

Loop through each cell in a given range and change the value depending on value in a column in the same row

Use match() and if() without code at ...READ MORE

answered Mar 26, 2023 in Others by Kithuzzz
• 38,000 points
927 views
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