VBA Scan column is case of blank cell copy the cell to the right in the blank cell
Hello All,
I'm looking for a piece of code that wil scan a column and when it comes on a blank cell or empty cell it wil copy the cel on the right and past it in the blank cell and then continiues.
Re: VBA Scan column is case of blank cell copy the cell to the right in the blank cel
My column to be "scanned" is A, starting in row 1. My column from which to grab the values to populate the blank cells is B.
Code:
Sub fillBlanks()
Dim i As Integer
Dim lastRow As Integer
Dim ws As Worksheet
Set ws = ActiveSheet
lastRow = ws.Range("a" & Rows.Count).End(xlUp).Row
For i = 1 To lastRow
If ws.Range("a" & i).Value = "" Then
ws.Range("a" & i).Value = ws.Range("b" & i).Value
End If
Next i
End Sub
Re: VBA Scan column is case of blank cell copy the cell to the right in the blank cel
I don't understand what's not working exactly. The file I attached in post #5 has strings in columns E and F and looks to work how you want it to. Did you run the macro in it and find it not to fill in the blanks as you'd expected?