need apply formula with variable amount of selected cells

Hordraric

New Member
Joined
Dec 19, 2018
Messages
2
Hello everyone,

im sorry if i dont express myself in the best way or if this question is already explained in full detail on the forums, is that i am new to VBA and excel macros (self-learning) and someone you dont know the names of stuff so when you search for it you might not find what you looking for due to not know the specific names for it.
my problem is the following: i have many tables that i want to apply the following formula: =Sum(A22:AX) being X the last cell of column A with a value. The thing is that X value varies from table to table and each time i apply record macro it writes down a specific number and therefore it cant be applied onto tables with different size.
so my question is if there is some way to specify a range/selection without being too specific, namely say which cell it is but rather a general and adjustable code.

Best regards and thank you for whoever can help me with this,
Hordraric
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
I would say no. One way to solve it would be to find the last column for each sheet and then apply that number to the code.
<code class="plain">
Code:
LastColumn = CellInRow.</code><code class="keyword">End</code><code class="plain">(xlToRight).Column</code><code class="plain">
</code>
 
Upvote 0
To sum from A22 to last cell with data in column A with result after last cell with data in column A. One way...

Code:
Sub sumit()
Dim xRng As Range
Set xRng = Range("A" & Rows.Count).End(xlUp)
xRng(2).Formula = "=SUM(A22:A" & xRng.Row & ")"
End Sub
 
Last edited:
Upvote 0
To sum from A22 to last cell with data in column A with result after last cell with data in column A. One way...

Code:
Sub sumit()
Dim xRng As Range
Set xRng = Range("A" & Rows.Count).End(xlUp)
xRng(2).Formula = "=SUM(A22:A" & xRng.Row & ")"
End Sub


omg thank you so much!!! it works T-T
 
Upvote 0
No problem and welcome to the board.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,214
Messages
6,170,772
Members
452,353
Latest member
strainu

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