Dynamic range based on column order

Haikal

New Member
Joined
Jan 16, 2014
Messages
28
Hi
I want to refer to columns by column order (i.e. A=1, B=2, etc.)

I want to sum a range for dynamic columns and fixed widths (i.e. B2:B5 or F2:F5, etc).

i have C_N as variant and i am trying to write the formula but desperately getting syntax error.

Code:
Range("M5") = WorksheetFunction.Sum(Range(C_N& "2" : C_N&"5")))

i tried before to make another easier formula like
Code:
=Range("N5:N" & LastRow)
and it worked.

Kindly advise
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
You could use a for loop:

Code:
For x = 2 to 6 Step 4
     ' Your code goes here
     msgbox Excel.WorksheetFunction.Sum(Range(Cells(2, x),Cells(5, x)))
Next x
 
Upvote 0
This is not what i need, i need to refer to the column number as i am doing this in other context, the columns are read in a listbox, so i need to calculate a formula for the selected listbox item (i.e. selected Column).
 
Upvote 0

Forum statistics

Threads
1,223,230
Messages
6,170,883
Members
452,364
Latest member
springate

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