IF function (copy cell) in a macro

A

Aline

I still do get it, can anyone help me with this?

Thanks,
-- > > How do I change the code so it will copy the content of column B to
column
Aline
 
T

TomPl

Try this:

Sub testit()

Dim LastRow As Long
Dim RowCount As Long

With ActiveSheet
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
For RowCount = 2 To LastRow
Range("C" & RowCount).Value = Range("B" & RowCount).Value
Next RowCount
End With
End Sub
 
T

TomPl

Sorry, I wasn't paying attention. You wanted an if statement and then a
formula. Try this instead:

Sub testit()

Dim LastRow As Long
Dim RowCount As Long

With ActiveSheet
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
For RowCount = 2 To LastRow
If Range("A" & RowCount).Value = "cat" Then
Range("C" & RowCount).Formula = "= IF(A2=""Cat"", B2, "" "")"
End If
Next RowCount
End With
End Sub
 
T

TomPl

I missed again! Try this, but wouldn't it be easier to simply copy the
formula down the column?:

Sub testit()

Dim LastRow As Long
Dim RowCount As Long

With ActiveSheet
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
For RowCount = 2 To LastRow
If Range("A" & RowCount).Value = "cat" Then
Range("C" & RowCount).Formula = "= IF(A" & RowCount & "=""Cat"", B" &
RowCount & ", "" "")"
End If
Next RowCount
End With
End Sub
 
Top