Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 59
Default VBA to -0- an amount during a Copy/Paste of a range of cells

2003

Row A B C
1 11 13 1000
2 12 12 3333
3 13 24 2222
4 14 32 4444

The Range being Copy/Paste is "C1:C4"
Using the table above, how do I make the amount Col "C" = 0 if the
value in Col "A" and Col "B" are equal?

Therefore, the Copy/Paste of "C1:C4" becomes:

Row A B C
1 11 13 1000
2 12 12 0
3 13 24 2222
4 14 32 4444

The challenge, as I see it, is what VBA code can I use to evaluate the
array as a whole and zero the amounts as defined above.

I realize that I can do a "Do While - Loop" on the worksheet range
after the Paste but that is slower and possibly not the smartest way to
accomplish the task.

The lines of code that I am using follow:

'Copies range from "Sheet1" to "Sheet2"
MyRngToCopy.Offset(0, 5).Resize(, 1).Copy
Sheets("Sheet2").Range("D" & CopyToRngRows).PasteSpecial
Paste:=xlPasteValues

TIA EagleOne

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default VBA to -0- an amount during a Copy/Paste of a range of cells

You are already using the best approach:


Sub demo()
Dim r As Range, r2 As Range
Set r = Sheets("Sheet1").Range("A1:C4")
Set r2 = Sheets("Sheet2").Range("A1")

r.Copy r2

Sheets("Sheet2").Activate
For i = 1 To 4
If Cells(i, "A").Value = Cells(i, "B").Value Then
Cells(i, "C").Value = 0
End If
Next

End Sub

--
Gary's Student


"Dennis" wrote:

2003

Row A B C
1 11 13 1000
2 12 12 3333
3 13 24 2222
4 14 32 4444

The Range being Copy/Paste is "C1:C4"
Using the table above, how do I make the amount Col "C" = 0 if the
value in Col "A" and Col "B" are equal?

Therefore, the Copy/Paste of "C1:C4" becomes:

Row A B C
1 11 13 1000
2 12 12 0
3 13 24 2222
4 14 32 4444

The challenge, as I see it, is what VBA code can I use to evaluate the
array as a whole and zero the amounts as defined above.

I realize that I can do a "Do While - Loop" on the worksheet range
after the Paste but that is slower and possibly not the smartest way to
accomplish the task.

The lines of code that I am using follow:

'Copies range from "Sheet1" to "Sheet2"
MyRngToCopy.Offset(0, 5).Resize(, 1).Copy
Sheets("Sheet2").Range("D" & CopyToRngRows).PasteSpecial
Paste:=xlPasteValues

TIA EagleOne


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
How to copy a range of cells and paste into a new workbook in differentcolumns Mas[_4_] Excel Discussion (Misc queries) 3 August 16th 11 02:57 PM
Copy & Paste Across Sheet Tabs in a Range of Cells Karen Excel Discussion (Misc queries) 4 November 11th 08 09:25 PM
copy/paste won't refer to the appropriate range of cells debandstormy Excel Discussion (Misc queries) 1 August 30th 06 02:29 AM
Macro to copy range of cells and paste into 1 sheet Dean[_9_] Excel Programming 2 February 20th 06 12:53 AM
Copy/paste range without resizeing cells konpego Excel Programming 2 February 11th 05 03:03 PM


All times are GMT +1. The time now is 11:36 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"