Find & replace up to certain row

srosk

Board Regular
Joined
Sep 17, 2018
Messages
132
Is there a way for this code to only look until the last populated row in column A vs the entire columns D:K. IE, the data stops on row 84, but the following populates ' N/A' all the way down D:K where a cell is blank.

Thanks in advance!


Code:
    Columns("D:K").Select    Selection.Replace What:="", Replacement:="       N/A", lookat:=xlWhole, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Are those cells actually blank, or do they contain formulae that return ""
 
Upvote 0
In that case, try
Code:
Sub srosk()
Range("D:K").EntireColumn.SpecialCells(xlBlanks).Value = "       N/A"
End Sub
 
Upvote 0
Thanks.. can check soon. So if cell A86 has a value and D is blank, " N/A" will appear in D86.

If A87 is blank, will D87 still be updated to " N/A" ? Ideally, it would remain blank (if possible). Not sure that logic is built in? Thanks again, as allways, Fluff! :)
 
Upvote 0
That will fill any blank cells in the used range for cols D:K with N/A
 
Upvote 0
Is there a way for it to determine the row to stop on.. IE: stop at row 86 since row 87 onward is not used?
 
Upvote 0
It only acts on the UsedRange, so if row 86 is the last row in the used range, that is where it will stop.
 
Upvote 0
Ok, my bad. I see what's happening. I copy 395 rows, do vlookups, and delete all rows where the vlookup result is #N/A, using a autofilter command. I think the UsedRange formula is still reading the blank rows 85-395 for some reason. I will try and figure out how to truly delete them.

Another issue that I am having, is that it does not actually fill in the columns where a row has data. For instance... J6 is blank. E6:I6 have values. When I run your formula, " N/A" does not populate in J6. Any idea about this one? I tried the following, but it didn't yield different results.

Code:
Range("D:D").EntireColumn.SpecialCells(xlBlanks).Value = "       N/A"
Range("E:E").EntireColumn.SpecialCells(xlBlanks).Value = "       N/A"
Range("F:F").EntireColumn.SpecialCells(xlBlanks).Value = "       N/A"
Range("G:G").EntireColumn.SpecialCells(xlBlanks).Value = "       N/A"
Range("H:H").EntireColumn.SpecialCells(xlBlanks).Value = "       N/A"
Range("I:I").EntireColumn.SpecialCells(xlBlanks).Value = "       N/A"
Range("J:J").EntireColumn.SpecialCells(xlBlanks).Value = "       N/A"
Range("K:K").EntireColumn.SpecialCells(xlBlanks).Value = "       N/A"

Thanks as always!
 
Last edited:
Upvote 0
So I think I got it... this fills in the N/A value, then deletes everything below where column A is blank :)

Code:
    Columns("D:K").Select    Selection.Replace What:="", Replacement:="       N/A", lookat:=xlWhole, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
        
   Columns("A:A").Select
   Selection.SpecialCells(xlCellTypeBlanks).Select
   Selection.EntireRow.Delete
 
Upvote 0

Forum statistics

Threads
1,213,527
Messages
6,114,148
Members
448,552
Latest member
WORKINGWITHNOLEADER

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