VBA Sum formula of a union of two ranges

Hermac

New Member
Joined
Sep 5, 2016
Messages
28
Office Version
  1. 365
Platform
  1. Windows
Hello

Could anyone tell me what I do wrong here ?

Sub TestSumFormula()

Dim R As Range

Set R = Union([J3:J22], [J25:J34])

MsgBox R.Address(1, 0)

[J35].Formula "=sum(" & R.Address(1, 0) & ")"

End Sub

MsgBox says “J$3:J$22,J$25:J$34” as expected but [J35] disappoints me with an Error 438.

Thanks a lot for any tip or better formula code for “sum” of a Union range, all cells of which are numbers.
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
So close! You were just missing an equal sign.

This:
VBA Code:
[J35].Formula "=sum(" & R.Address(1, 0) & ")"
should be this:
VBA Code:
[J35].Formula = "=sum(" & R.Address(1, 0) & ")"
 
Upvote 0
Solution
Wow, Thanks a truckload Joe4. How could I not have noticed this after meticulously staring at this line for half an hour. Anyway, you made my day and stopped me loosing time.
Ofcourse, your answer is the only one and it solved my problem right away. But now again I can't even find the "Mark as solution" button that i'd like to click with an exclamation mark. I'm not drunk though, maybe just stupid or just age 75.
Have a beautiful day.
Herman
 
Upvote 0
Wow, Thanks a truckload Joe4. How could I not have noticed this after meticulously staring at this line for half an hour. Anyway, you made my day and stopped me loosing time.
Ofcourse, your answer is the only one and it solved my problem right away. But now again I can't even find the "Mark as solution" button that i'd like to click with an exclamation mark. I'm not drunk though, maybe just stupid or just age 75.
Have a beautiful day.
Herman
You are welcome.
I marked it for you. It is the check mark icon to the right of the post you want to mark.

No worries! Sometimes you just need a second set of eyes to look at it. I have the same issue myself sometimes. I will be starting at it, and I see what I want to see, and not what is really there!
I find sometimes if I put it away and come back to it the next day, I have a better chance of spotting the error myself (but not always!).
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top