Excel Macro VBA I have two sheets of data in an excel file. I want to loop through all the columns and all the rows to check if the cells are empty.
I am trying to replace a word from the "TemplateSheet".
"DataSheet" contains the words for replacement.
But it seems like my while loop doesn't work on looping through the columns. Can you help out?
While Sheets("DataSheet").Cells(1, iColumn) <> ""
While Sheets("DataSheet").Cells(iRow, 1) <> ""
Dim sReplace As String
sReplace = Sheets("DataSheet").Cells(iRow, 1)
sTemplate = Sheets("TemplateSheet").Cells(1, 1)
sFind = Sheets("DataSheet").Cells(1, iColumn)
sTemplate = Replace(sTemplate, sFind, sReplace)
MsgBox sTemplate
iRow = iRow + 1
Wend
iColumn = iColumn + 1
Wend
Thanks for the help.
iRowandiColumnvariables initialized to? I also think that yourWhileclauses need a.Valueafter the.Cellsbit, so it looks likeWhile Sheets("DataSheet").Cells(1, iColumn).Value <> "", it may be comparing an actual cell to an empty string.sTemplateto the first cell ofTemplateSheetonly to set it to something else two lines later?