Add a range to antoher range

  • Thread starter Thread starter jlclyde
  • Start date Start date
J

jlclyde

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
 
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
 
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




- 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
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top