PDA

View Full Version : Solved: macro help



oleg_v
01-29-2010, 08:06 AM
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

krishhi
01-29-2010, 08:24 AM
Hi dude,

check this code:


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

Keep Smiling

MaximS
01-29-2010, 08:34 AM
try that mate:



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

mdmackillop
01-30-2010, 09:02 AM
You can skip checking evey cell in the range

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

ZVI
01-30-2010, 10:36 PM
And one more one :)


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
P.S. Not sure that I’ve understood the task correctly, Oleg if it's more suitable you can ask me by PM on Russian