help with xltoright & last col

oddworld

Board Regular
Joined
May 31, 2005
Messages
248
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

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result

jindon

MrExcel MVP
Joined
Aug 21, 2004
Messages
16,995
Hi

1) Isn't it xlToLeft?
2) Can you show us actual formula in the cell?
 

HalfAce

MrExcel MVP
Joined
Apr 6, 2003
Messages
9,456
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.
 

oddworld

Board Regular
Joined
May 31, 2005
Messages
248
re

jindon in "h20" i have the following formula "=SUM(Q28:AB28)/(((AVERAGE(P27,AB27)+SUM(Q27:AA27))/12))"
 

jindon

MrExcel MVP
Joined
Aug 21, 2004
Messages
16,995
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)) "
 

Forum statistics

Threads
1,144,394
Messages
5,724,087
Members
422,536
Latest member
Zeeshan53

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
Top