Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 43
Default 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   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 342
Default 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   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 342
Default 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   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 342
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
IF function (copy cell) in a macro Aline Excel Discussion (Misc queries) 4 July 28th 08 06:32 PM
Macro copy function Nick Krill Excel Discussion (Misc queries) 1 April 4th 07 07:03 PM
copy name from active sheet to cell - using macro or function dymek Excel Worksheet Functions 2 October 2nd 06 12:32 PM
Using macro to copy a part of a cell content to next cell Charles Excel Discussion (Misc queries) 6 May 31st 06 05:57 AM
If than copy function / Macro Sweetetc Excel Worksheet Functions 2 April 7th 06 06:30 PM


All times are GMT +1. The time now is 11:21 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"