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
1,027
Office Version
  1. 365
Platform
  1. Windows
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

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
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"
 
Upvote 0
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
 
Upvote 0
(y)

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

Forum statistics

Threads
1,214,631
Messages
6,120,640
Members
448,974
Latest member
DumbFinanceBro

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