Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.misc
|
|||
|
|||
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 |
#2
Posted to microsoft.public.excel.misc
|
|||
|
|||
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 |
#3
Posted to microsoft.public.excel.misc
|
|||
|
|||
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 |
#4
Posted to microsoft.public.excel.misc
|
|||
|
|||
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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
IF function (copy cell) in a macro | Excel Discussion (Misc queries) | |||
Macro copy function | Excel Discussion (Misc queries) | |||
copy name from active sheet to cell - using macro or function | Excel Worksheet Functions | |||
Using macro to copy a part of a cell content to next cell | Excel Discussion (Misc queries) | |||
If than copy function / Macro | Excel Worksheet Functions |