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

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
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,641
Messages
6,120,694
Members
448,979
Latest member
DET4492

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