How to set variable range using a macro

coop123

Board Regular
Joined
Dec 18, 2018
Messages
66
Office Version
  1. 365
Hello

I have a macro in which I need to add a SUMIF formula which has the criteria range as fixed so I can copy across range of columns. The column length is the same across the report, but each time the report is run the column length can vary.

To get the last row in a column I have used

Dim ListEnd As Integer

This works fine and gives the correct result. See below.

Range("M701").Formula = "=SUMIF(A12:A" & ListEnd & ",""EU"",M12:M" & ListEnd & ")"

My problem is I need A12:A to be fixed when I copy formula across other columns.

Any help would be much appreciated

Coop123
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
How about
VBA Code:
"=SUMIF($A12:$A" & ListEnd & ",""EU"",M12:M" & ListEnd & ")"
 
Upvote 0
Solution
Hello Fluff

That works perfect.

I have been looking at complicated ways of trying to fix the range.

Should try to keep things simple.

Thanks again.

Coop123
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,326
Messages
6,124,258
Members
449,149
Latest member
mwdbActuary

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