Hi, I'm getting extremely frustrated here trying to simply use VBA to get the Max of the currently selected cells or range.
I'm trying to insert the code into an already functioning sub in an Access db which draws multiple bar charts for a spreadsheet. I want the Max value so that I can scale the graphs in a different way to what the autoscale function does.
I know this works:
because I've been using it for months.
After some trouble and coffee I managed:
Which works, but seems silly - is there any way I can use the Max function with the currently selected cells?
What this comes down to is I really don't know how to refer to the active range...
Help please?
Phil
Phil
---------------
Pass me the ether.
I'm trying to insert the code into an already functioning sub in an Access db which draws multiple bar charts for a spreadsheet. I want the Max value so that I can scale the graphs in a different way to what the autoscale function does.
I know this works:
Code:
'Select data range for graph on pctresults sheet
ExcelApp.Worksheets("PctResults").Activate
With ExcelApp.ActiveSheet
.Range(.Cells(StartRow, StartColumn), .Cells(EndRow, EndColumn)).Select
End With
'NEW CODE TO GO HERE
'Create graph object
Set ObjExChart = ObjExcel.Charts.Add
After some trouble and coffee I managed:
Code:
Dim rngdata As Range
Set rngdata = ExcelApp.ActiveSheet.Cells(StartRow, StartColumn).Resize(EndRow - StartRow, 1)
MaxEco = ExcelApp.WorksheetFunction.Max(rngdata)
Which works, but seems silly - is there any way I can use the Max function with the currently selected cells?
What this comes down to is I really don't know how to refer to the active range...
Help please?
Phil
Phil
---------------
Pass me the ether.