Cell Range

Matt

Board Regular
Joined
Feb 16, 2002
Messages
212
I'm currently using this code to find my starting row for a range, how can I declare this as my starting row?

thanks

Matt

Cells.Find(What:="CURRENT MONTH TO DATE TOTALS", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=True).Activate
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Hi Matt

Just use:

Dim rStartRange As Range
Set rStartRange = Cells.Find(What:="CURRENT MONTH TO DATE TOTALS", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=True)
 
Upvote 0
Dave

I've tried to use the rStartRange as part of a macro for producing a chart but it is falling down on the "Set rStartRange" line. Can you spot why it is falling down, error messsage is Method 'Cells' of Object '_Global' failed

Sub SSChart()

Dim Cht As Chart
Dim Lastrow As Long
Dim CurrentSheet As String
Dim rStartRange As Range

Set rStartRange = Cells.Find(What:="CURRENT MONTH TO DATE TOTALS", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=True)


CurrentSheet = ActiveSheet.Name


Set Cht = Application.Charts.Add
Lastrow = Sheets(CurrentSheet).Range("A100").End(xlUp).Row


With Cht
.ChartType = xlXYScatter
.SetSourceData Source:=Sheets(CurrentSheet).Range("A" & rStartRange & ":A" & Lastrow & ",D" & rStartRange & ":D" & Lastrow), PlotBy:=xlColumns
.SeriesCollection(1).XValues = Worksheets(CurrentSheet).Range("A" & rStartRange & ":A" & Lastrow)
.SeriesCollection(1).Values = Worksheets(CurrentSheet).Range("D" & rStartRange & ":D" & Lastrow)
.Location Where:=xlLocationAsObject, Name:=CurrentSheet
End With

End Sub
 
Upvote 0
How are you running the macro, if via a CommandButton from the Control toolbox set it's "TakeFocusOnClick" property to false. Or better still use a CommandButton from the Forma toolbar.
 
Upvote 0

Forum statistics

Threads
1,214,826
Messages
6,121,794
Members
449,048
Latest member
greyangel23

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