PDA

View Full Version : If then Else to fill blank cells



Zlerp
11-20-2014, 09:28 AM
Hello All,

i am looking for a macro that will look in column B for any blanks, if there is a blank cell in B, then i want it to copy and paste the data from the cell in column A into column B.

So for example. I have 10 rows x 2 columns of data.
(there will be much more than 10 rows on the real worksheet, This macro should loop to last row)

The Macro looks in collumn B and finds that B6 and B4 is Null. It will then copy and paste A6 to B6 and A4 to B4, and continue to last row.



A

B



1

2

1



2

2

1



3

2

1



4

3

3



5

2

1



6

2

2



7

2

1



8

2

1



9

2

1



10

2

1




Thank you for your time,
Zlerp

ashleyuk1984
11-20-2014, 04:00 PM
Sub Zlerp()

LastRow = Range("A" & Rows.Count).End(xlUp).Row


For x = 1 To LastRow
If Range("B" & x).Value = "" Then Range("B" & x).Value = Range("A" & x).Value
Next x


End Sub

Paul_Hossler
11-22-2014, 01:28 PM
also



Sub FillBlanks()
Dim r As Range
On Error Resume Next
For Each r In ActiveSheet.Cells(1, 1).CurrentRegion.Columns(2).SpecialCells(xlCellTypeBlanks)
r.Value = r.Offset(0, -1).Value
Next
On Error GoTo 0
End Sub