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.
Hope you could help?
Kind regards,
Arne
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
Re: VBA Scan column is case of blank cell copy the cell to the right in the blank cel
Hello Bryce,
I've tried this on column E and F but it didnt work as there is text in these rows.
When i've added numbers in E and F it did work.
Hmmm Could you help?
Sub fillBlanks()
Dim i As Integer
Dim lastRow As Integer
Dim ws As Worksheet
Set ws = ActiveSheet
lastRow = ws.Range("e" & Rows.Count).End(xlUp).Row
For i = 1 To lastRow
If ws.Range("e" & i).Value = "" Then
ws.Range("e" & i).Value = ws.Range("f" & i).Value
End If
Next i
End Sub
1 Attachment(s)
Re: VBA Scan column is case of blank cell copy the cell to the right in the blank cel
shouldn't matter if it's numbers or text. see attached and let me know if yours is different.
Re: VBA Scan column is case of blank cell copy the cell to the right in the blank cel
There is something with the cells in row E and F tried to delete all formulas and make the cells nutral. Save the file in a different formate
Your code works like clockwork in any other cells......
unfortunatly I can't post the file here....:o
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?
Re: VBA Scan column is case of blank cell copy the cell to the right in the blank cel
The file when it opens is in .csv format when I save it in .xls it works but only in a few cells then it stops...