Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default range with variable row

I have a macro with a loop From r = 14 to lastrow
I need to define a Range with Row r and Columns "D" to "P"

What is the correct syntax to define the range with a variable row?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default range with variable row



set myrange = Range("D" & r & ":P" & r)

"Bonobo" wrote:

I have a macro with a loop From r = 14 to lastrow
I need to define a Range with Row r and Columns "D" to "P"

What is the correct syntax to define the range with a variable row?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default range with variable row

thanks!

what if I want a range of cells that are not contiguous?
Let's say a range with cells in row r and columns D, F and H (r being a loop
from 14 to lastrow )

"Joel" wrote:



set myrange = Range("D" & r & ":P" & r)

"Bonobo" wrote:

I have a macro with a loop From r = 14 to lastrow
I need to define a Range with Row r and Columns "D" to "P"

What is the correct syntax to define the range with a variable row?

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default range with variable row

range doesn't have to be continous.

Range("A1,D5, E4:G8") = 5

The numbers can be replace by variable

MyRow = 4
Range("A1,D5, E" & Myrow & ":G8") = 5

"Bonobo" wrote:

thanks!

what if I want a range of cells that are not contiguous?
Let's say a range with cells in row r and columns D, F and H (r being a loop
from 14 to lastrow )

"Joel" wrote:



set myrange = Range("D" & r & ":P" & r)

"Bonobo" wrote:

I have a macro with a loop From r = 14 to lastrow
I need to define a Range with Row r and Columns "D" to "P"

What is the correct syntax to define the range with a variable row?

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default range with variable row

so would this syntax be correct?

With ActiveChart.SeriesCollection.NewSeries
..Values = ActiveSheet.Range("E" & r, "H" & r, "K" & r, "N" & r, "Q" & r)

It is giving me an error 450: Wrong number of arguments or invalid property
assignment

What am I doing wrong?

"Joel" wrote:

range doesn't have to be continous.

Range("A1,D5, E4:G8") = 5

The numbers can be replace by variable

MyRow = 4
Range("A1,D5, E" & Myrow & ":G8") = 5

"Bonobo" wrote:

thanks!

what if I want a range of cells that are not contiguous?
Let's say a range with cells in row r and columns D, F and H (r being a loop
from 14 to lastrow )

"Joel" wrote:



set myrange = Range("D" & r & ":P" & r)

"Bonobo" wrote:

I have a macro with a loop From r = 14 to lastrow
I need to define a Range with Row r and Columns "D" to "P"

What is the correct syntax to define the range with a variable row?



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default range with variable row

The commas have to be in the quoted strings

from
With ActiveChart.SeriesCollection.NewSeries
..Values = ActiveSheet.Range("E" & r, "H" & r, "K" & r, "N" & r, "Q" & r)

to
With ActiveChart.SeriesCollection.NewSeries
..Values = ActiveSheet.Range("E" & r & ",H" & r & ",K" & r & ",N" & r & ",Q"
& r)

I tested it with the following code ancd it works. With your code it gave
me an error.
r = 1
ActiveSheet.Range("E" & r & ",H" & r & ",K" & r & ",N" & r & ",Q" & r).Select

I'm not sure if it will work with a series collection.

"Bonobo" wrote:

so would this syntax be correct?

With ActiveChart.SeriesCollection.NewSeries
.Values = ActiveSheet.Range("E" & r, "H" & r, "K" & r, "N" & r, "Q" & r)

It is giving me an error 450: Wrong number of arguments or invalid property
assignment

What am I doing wrong?

"Joel" wrote:

range doesn't have to be continous.

Range("A1,D5, E4:G8") = 5

The numbers can be replace by variable

MyRow = 4
Range("A1,D5, E" & Myrow & ":G8") = 5

"Bonobo" wrote:

thanks!

what if I want a range of cells that are not contiguous?
Let's say a range with cells in row r and columns D, F and H (r being a loop
from 14 to lastrow )

"Joel" wrote:



set myrange = Range("D" & r & ":P" & r)

"Bonobo" wrote:

I have a macro with a loop From r = 14 to lastrow
I need to define a Range with Row r and Columns "D" to "P"

What is the correct syntax to define the range with a variable row?

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default range with variable row

you're right, it is giving an error in the compilation.
Would you know the syntax to include a variable in the R1C2 format?

I would like to try with the below format, but would need to replace the 13
with a variable r:

..Values = "=(ActiveSheet!R13C5, ActiveSheet!R13C8, ActiveSheet!R13C11,
ActiveSheet!R13C14, ActiveSheet!R13C17)"


"Joel" wrote:

The commas have to be in the quoted strings

from
With ActiveChart.SeriesCollection.NewSeries
.Values = ActiveSheet.Range("E" & r, "H" & r, "K" & r, "N" & r, "Q" & r)

to
With ActiveChart.SeriesCollection.NewSeries
.Values = ActiveSheet.Range("E" & r & ",H" & r & ",K" & r & ",N" & r & ",Q"
& r)

I tested it with the following code ancd it works. With your code it gave
me an error.
r = 1
ActiveSheet.Range("E" & r & ",H" & r & ",K" & r & ",N" & r & ",Q" & r).Select

I'm not sure if it will work with a series collection.

"Bonobo" wrote:

so would this syntax be correct?

With ActiveChart.SeriesCollection.NewSeries
.Values = ActiveSheet.Range("E" & r, "H" & r, "K" & r, "N" & r, "Q" & r)

It is giving me an error 450: Wrong number of arguments or invalid property
assignment

What am I doing wrong?

"Joel" wrote:

range doesn't have to be continous.

Range("A1,D5, E4:G8") = 5

The numbers can be replace by variable

MyRow = 4
Range("A1,D5, E" & Myrow & ":G8") = 5

"Bonobo" wrote:

thanks!

what if I want a range of cells that are not contiguous?
Let's say a range with cells in row r and columns D, F and H (r being a loop
from 14 to lastrow )

"Joel" wrote:



set myrange = Range("D" & r & ":P" & r)

"Bonobo" wrote:

I have a macro with a loop From r = 14 to lastrow
I need to define a Range with Row r and Columns "D" to "P"

What is the correct syntax to define the range with a variable row?

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default range with variable row

Simple

r = 13
..Values = "=(ActiveSheet!R" & r & "C5, ActiveSheet!R" _
& r & "C8, ActiveSheet!R" & r & _
"C11,ActiveSheet!R" & r & "C14, ActiveSheet!R" & r & "C17)"


"Bonobo" wrote:

you're right, it is giving an error in the compilation.
Would you know the syntax to include a variable in the R1C2 format?

I would like to try with the below format, but would need to replace the 13
with a variable r:

.Values = "=(ActiveSheet!R13C5, ActiveSheet!R13C8, ActiveSheet!R13C11,
ActiveSheet!R13C14, ActiveSheet!R13C17)"


"Joel" wrote:

The commas have to be in the quoted strings

from
With ActiveChart.SeriesCollection.NewSeries
.Values = ActiveSheet.Range("E" & r, "H" & r, "K" & r, "N" & r, "Q" & r)

to
With ActiveChart.SeriesCollection.NewSeries
.Values = ActiveSheet.Range("E" & r & ",H" & r & ",K" & r & ",N" & r & ",Q"
& r)

I tested it with the following code ancd it works. With your code it gave
me an error.
r = 1
ActiveSheet.Range("E" & r & ",H" & r & ",K" & r & ",N" & r & ",Q" & r).Select

I'm not sure if it will work with a series collection.

"Bonobo" wrote:

so would this syntax be correct?

With ActiveChart.SeriesCollection.NewSeries
.Values = ActiveSheet.Range("E" & r, "H" & r, "K" & r, "N" & r, "Q" & r)

It is giving me an error 450: Wrong number of arguments or invalid property
assignment

What am I doing wrong?

"Joel" wrote:

range doesn't have to be continous.

Range("A1,D5, E4:G8") = 5

The numbers can be replace by variable

MyRow = 4
Range("A1,D5, E" & Myrow & ":G8") = 5

"Bonobo" wrote:

thanks!

what if I want a range of cells that are not contiguous?
Let's say a range with cells in row r and columns D, F and H (r being a loop
from 14 to lastrow )

"Joel" wrote:



set myrange = Range("D" & r & ":P" & r)

"Bonobo" wrote:

I have a macro with a loop From r = 14 to lastrow
I need to define a Range with Row r and Columns "D" to "P"

What is the correct syntax to define the range with a variable row?

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Range to VLOOKUP as a Variable (range in another file) LuisE Excel Programming 3 December 2nd 07 03:22 PM
select range and put range address in variable [email protected] Excel Programming 2 January 25th 06 01:28 AM
Macro to copy a specified range to a variable range SWT Excel Programming 4 October 21st 05 08:24 PM
setting a range variable equal to the value of a string variable Pilgrim Excel Programming 2 July 1st 04 11:32 PM
Problem trying to us a range variable as an array variable TBA[_2_] Excel Programming 4 September 27th 03 02:56 PM


All times are GMT +1. The time now is 11:49 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"