Hi
i need help with some macro.
i have 2 columns.
What i need this if the cell in column "D" is empty copy the contaimnet of the cell in column "B" on the same row and if both of the cell is empty live it empty!
Thanks
Printable View
Hi
i need help with some macro.
i have 2 columns.
What i need this if the cell in column "D" is empty copy the contaimnet of the cell in column "B" on the same row and if both of the cell is empty live it empty!
Thanks
Hi dude,
check this code:
Keep SmilingCode:Sub test()
Dim i As Integer, lr As Integer
lr = ActiveSheet.UsedRange.Rows.Count
For i = 1 To lr
If Range("D" & i).Value = "" Then
Range("D" & i).Value = Range("B" & i).Value
End If
Next
End Sub
try that mate:
[VBA]
Sub tryme()
Dim lr As Long, i As Long
With Worksheets("YourWorksheetName")
lr = .Range("B" & .Rows.Count).End(xlUp).Row
For i = 2 To lr
If .Cells(i, "D").Value = "" And .Cells(i, "B").Value <> "" Then
.Cells(i, "D").Value = .Cells(i, "B").Value
End If
Next i
End With
End Sub
[/VBA]
You can skip checking evey cell in the range
[VBA]
Dim Rng As Range, cel As Range
Set Rng = Range(Cells(1, 4), Cells(Rows.Count, 4).End(xlUp))
Set Rng = Rng.SpecialCells(xlCellTypeBlanks)
For Each cel In Rng
cel = cel.Offset(, -2)
Next
[/VBA]
And one more one :)
P.S. Not sure that I’ve understood the task correctly, Oleg if it's more suitable you can ask me by PM on RussianCode:
Sub Test1()
Const StartRow = 2 ' <-- Change to suit
With ActiveSheet.UsedRange
With Range(Cells(StartRow, "D"), Cells(.Row + .Rows.Count - 1, "D"))
.Value = .Offset(, -2).Value
End With
End With
End Sub