help with xltoright & last col

oddworld

Active Member
Joined
May 31, 2005
Messages
250
can somebody please advise me what i am doing wrong
my data lies in row 27 and row 28, and is updated monthly
i want the answer to be in "h20" (which is 8 rows above the data)
i can't figure out how to direct the macro to capture the last column to then apply the formula, i am also having drama's with" xltoright"
any advice would be appreciated
my macro so far seems to be capturing rows not columns and i am getting a circular ref as a result.

Sub seps_rate()
LastCol = Cells(8,Columns.Count).End(xlToRight).Columns
Range("h20").Formula = "=SUM( 28" & LastCol - 11 & ":28" & LastCol & ") / (((AVERAGE( 27t" & LastCol - 12 & ",27" & LastCol & ")+ SUM( 27" & LastCol - 1 & ":27 " & LastCol - 1 & "))/12)) "

End Sub
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
i am also having drama's with" xltoright"
Hello oddworld,
The bit Columns.Count is referring to (in present versions of excel) column IV (or column 256)
- and you can't go any further right from there.
I believe what you want to use is:
LastCol = Cells(8,Columns.Count).End(xlToLeft).Column

This will start in column 256 and work left to give you the column (number) of the last used
column in row 8.
 
Upvote 0
re

jindon in "h20" i have the following formula "=SUM(Q28:AB28)/(((AVERAGE(P27,AB27)+SUM(Q27:AA27))/12))"
 
Upvote 0
Hi
try
this is assuming LastCol = 28 (AB)
Code:
Range("h20").Formula = "=SUM(" & Cells(28, LastCol -11).Resize(,12).Address & ") / (((AVERAGE(" & Cells(27, LastCol -12).Resize(,12).Address & ")+ SUM(" & Cells(27, LastCol - 11).Resize(,11).Address & "))/12)) "
 
Upvote 0

Forum statistics

Threads
1,214,561
Messages
6,120,242
Members
448,951
Latest member
jennlynn

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