Printable Version of Topic

Click here to view this topic in its original format

UtterAccess Forums _ Microsoft Excel _ Find And Replace Blanks (vba)

Posted by: ws1o Jan 3 2020, 11:03 AM

I'm running some VBA code from an MS Access application that has to fix up values in an Excel worksheet.

It needs to go through a huge worksheet (500,000 rows) and find all blank values in Column D and replace them with the values from column A (in the same row as the blank)

I wrote some code that walks down the rows and does this, but it's glacially slow.

Then I tried this, but it just replaces the blanks with the header from row 1 of column A:

.Columns("AG").Replace What:="", Replacement:=.Columns("AD"), LookAt:=xlWhole, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False

Any suggestions?

Posted by: June7 Jan 3 2020, 04:03 PM

If you only want to replace Column D with values from Column A, why reference multi-column range? I tried your code and I get "type mismatch" error on the Replacement argument. If I use a literal value like "X", no error but no edits either. I change "AG" to "D" and it does replace empty cells with "X"

So I am not sure this method can do the dynamic reference you want.