IF function (copy cell) in a macro
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 C? A B C Dog 2007-10-22 Cat 2008-02-02 2008-02-02 Cat 2008-02-11 Here are the codes: Dim LastRow As Long Dim wks As Worksheet Set wks = ActiveSheet With wks LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row .Range("C2:C" & LastRow).Formula _ = "= IF(A2=""Cat"", B2, "" "")" End With Thanks, Aline -- Aline Aline |
IF function (copy cell) in a macro
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 "Aline" wrote: 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 C? A B C Dog 2007-10-22 Cat 2008-02-02 2008-02-02 Cat 2008-02-11 Here are the codes: Dim LastRow As Long Dim wks As Worksheet Set wks = ActiveSheet With wks LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row .Range("C2:C" & LastRow).Formula _ = "= IF(A2=""Cat"", B2, "" "")" End With Thanks, Aline -- Aline Aline |
IF function (copy cell) in a macro
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 "TomPl" wrote: 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 "Aline" wrote: 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 C? A B C Dog 2007-10-22 Cat 2008-02-02 2008-02-02 Cat 2008-02-11 Here are the codes: Dim LastRow As Long Dim wks As Worksheet Set wks = ActiveSheet With wks LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row .Range("C2:C" & LastRow).Formula _ = "= IF(A2=""Cat"", B2, "" "")" End With Thanks, Aline -- Aline Aline |
IF function (copy cell) in a macro
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 "TomPl" wrote: 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 "TomPl" wrote: 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 "Aline" wrote: 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 C? A B C Dog 2007-10-22 Cat 2008-02-02 2008-02-02 Cat 2008-02-11 Here are the codes: Dim LastRow As Long Dim wks As Worksheet Set wks = ActiveSheet With wks LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row .Range("C2:C" & LastRow).Formula _ = "= IF(A2=""Cat"", B2, "" "")" End With Thanks, Aline -- Aline Aline |
All times are GMT +1. The time now is 07:44 AM. |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com