Find a column by name in row 1 and replace blank cells with the text "Blanks2"...

VBAProIWish

Well-known Member
Joined
Jul 6, 2009
Messages
980
Hi,

I'd like a macro to find the column named "Earth" in row 1 and replace ALL and ONLY blank cells with the text "Blanks2"...

BUT...

It should first look at the "Galaxy" column (also in row 1) to find the last row with data in it. Once it knows the last row of data in the "Galaxy" column, the macro should stop putting the text "Blanks2" in the "Earth" column.

This is because the "Earth" column will now have some form of text in every cell equal to the last data row in the "Galaxy" column.

Regards
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce

Fazza

MrExcel MVP
Joined
May 17, 2006
Messages
9,368
How is this?
Code:
Rows(1).Find(what:="Earth").Resize(Cells(Cells.Rows.Count, Rows(1).Find(what:="Galaxy").Column).End(xlUp).Row).SpecialCells(xlCellTypeBlanks).Value = "Blanks2"
 

VBAProIWish

Well-known Member
Joined
Jul 6, 2009
Messages
980
Fazza,

When I first saw this line of code I said to myself "huh, that's only 1 line, it can't be that short", but

INDEED IT IS!

Perfect!

Thank you Thank you!

Regards
 

Fazza

MrExcel MVP
Joined
May 17, 2006
Messages
9,368
(y)

Note, it will error if there are no blank cells, so please accommodate that in your code.
 

Forum statistics

Threads
1,143,656
Messages
5,720,116
Members
422,266
Latest member
Mattyw

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
Top