Change $A$1:$C$6500 to current region of A1 instead

VBAProIWish

Well-known Member
Joined
Jul 6, 2009
Messages
1,027
Office Version
  1. 365
Platform
  1. Windows
Hello All,

I have one this one line of code here and would like to change it to the current region of cell A1 instead of only going to 6500. The # of rows will get longer each month.

Code:
    ActiveChart.SetSourceData Source:=Range("GRAPES![B][SIZE=3][COLOR=red]$A$1:$C$6500[/COLOR][/SIZE][/B]")


I know I can just put in "$A$1:$C$1000000" but don't want to select unnecessary rows if I don't have to.


Thanks much :)
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
You could try this.
Code:
Worksheets("GRAPES").Range("A1").CurrentRegion
 
Upvote 0
Maybe this (untested)

Code:
ActiveChart.SetSourceData Source:=Sheets("GRAPES").Range("A1").CurrentRegion
 
Upvote 0
Both worked EXCEPT,

I forgot that some of my Worksheet names has more than one word with a space in between them.

For example, one of my worksheet names is "Cht-P, Park"...

so...I remembered that when there is a worksheet with spaces in the name and it has to be referred to, it must include single quotations in between the double quotations.

So, I tried this here...

Code:
Worksheets("'Cht-P, Park'").Range("A1").CurrentRegion


and this...

Code:
ActiveChart.SetSourceData Source:=Sheets("'Cht-P, Park'").Range("A1").CurrentRegion

With the single quotations and neither one worked.

Just when I thought I had worksheet names with spaces in code mastered :(

Any idea what's going on here?
 
Upvote 0
Yes, you don't need single quotes.
 
Upvote 0
Ahhh! Thank you!

So, why do you sometimes need the single quotes and sometimes not?
 
Upvote 0
Well,

Thank you both for the help!

My new VBA "learn" for the day!

:beerchug:
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,602
Messages
6,179,844
Members
452,948
Latest member
UsmanAli786

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