IF function (copy cell) in a macro

  • Thread starter Thread starter Aline
  • Start date Start date
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
 
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
 
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
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top