![]() |
Add a range to antoher range
I have a 2 ranges of cells that are equal size and I would ilke to add
them together. Here is where I am drawing a blank. say range("A1:A10" is the first range and Range("B1:B10") is the 2nd range. I woudl like to add A1 to B1 and A2 to B2 and so on. I want to skip cells if either one of them are text. I was thinking For each.... but do nto know what this would look like. Any help would be greatly appreciated. Thanks, Jay |
Add a range to antoher range
Do you mean that you want 10 results in, say, C1:C10, or that you want
one result of them all added together? When you say "skip cells if either of them are text", do you mean you want to ignore both A and B cells on that row if one contains text, or that you don't want to include the text value in the addition because it will cause an error? Are you trying to do this in a macro? Pete On Oct 30, 7:15*pm, jlclyde wrote: I have a 2 ranges of cells that are equal size and I would ilke to add them together. *Here is where I am drawing a blank. *say range("A1:A10" is the first range and Range("B1:B10") is the 2nd range. *I woudl like to add A1 to B1 and A2 to B2 and so on. *I want to skip cells if either one of them are text. *I was thinking For each.... but do nto know what this would look like. *Any help would be greatly appreciated. Thanks, Jay |
Add a range to antoher range
On Oct 30, 2:27*pm, Pete_UK wrote:
Do you mean that you want 10 results in, say, C1:C10, or that you want one result of them all added together? When you say "skip cells if either of them are text", do you mean you want to ignore both A and B cells on that row if one contains text, or that you don't want to include the text value in the addition because it will cause an error? Are you trying to do this in a macro? Pete On Oct 30, 7:15*pm, jlclyde wrote: I have a 2 ranges of cells that are equal size and I would ilke to add them together. *Here is where I am drawing a blank. *say range("A1:A10" is the first range and Range("B1:B10") is the 2nd range. *I woudl like to add A1 to B1 and A2 to B2 and so on. *I want to skip cells if either one of them are text. *I was thinking For each.... but do nto know what this would look like. *Any help would be greatly appreciated. Thanks, Jay- Hide quoted text - - Show quoted text - Pete, I am trying to do this in a macro and this is what I have come up with and it seems to work. Apparently all I needed to do was post and then the idea of isnumeric came to me. As you can see from the code I was trying to add the As to the Bs in column C and skip any of the cells where a or b was not a number. Here is the code I am using if any one is interested. Also if anyone knows a better way, I am open to suggestions. Sub AddRows() Dim rng1 As Range Dim i Set rng1 = Range("A20:A25") For Each i In rng1 If IsNumeric(i.Value) = True And IsNumeric(i.Offset(0, 1).Value) = True Then i.Offset(0, 2).Value = i.Value + i.Offset(0, 1).Value Else GoTo E End If E: Next i End Sub Thanks, Jay |
Add a range to antoher range
Glad you got to a solution, Jay.
Just one thing - you don't need to write: If IsNumeric(...) = True ... etc You can just write this as: If IsNumeric(...) And IsNumeric(...) Then Hope this helps. Pete On Oct 30, 7:33*pm, jlclyde wrote: On Oct 30, 2:27*pm, Pete_UK wrote: Do you mean that you want 10 results in, say, C1:C10, or that you want one result of them all added together? When you say "skip cells if either of them are text", do you mean you want to ignore both A and B cells on that row if one contains text, or that you don't want to include the text value in the addition because it will cause an error? Are you trying to do this in a macro? Pete On Oct 30, 7:15*pm, jlclyde wrote: I have a 2 ranges of cells that are equal size and I would ilke to add them together. *Here is where I am drawing a blank. *say range("A1:A10" is the first range and Range("B1:B10") is the 2nd range. *I woudl like to add A1 to B1 and A2 to B2 and so on. *I want to skip cells if either one of them are text. *I was thinking For each.... but do nto know what this would look like. *Any help would be greatly appreciated. Thanks, Jay- Hide quoted text - - Show quoted text - Pete, I am trying to do this in a macro and this is what I have come up with and it seems to work. *Apparently all I needed to do was post and then the idea of isnumeric came to me. *As you can see from the code I was trying to add the As to the Bs in column C and skip any of the cells where a or b was not a number. *Here is the code I am using if any one is interested. *Also if anyone knows a better way, I am open to suggestions. Sub AddRows() * * Dim rng1 As Range * * Dim i * * Set rng1 = Range("A20:A25") * * For Each i In rng1 * * * * If IsNumeric(i.Value) = True And IsNumeric(i.Offset(0, 1).Value) = True Then * * * * * * i.Offset(0, 2).Value = i.Value + i.Offset(0, 1)..Value * * * * Else * * * * * * GoTo E * * * * End If E: * * Next i End Sub Thanks, Jay- Hide quoted text - - Show quoted text - |
All times are GMT +1. The time now is 05:49 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com