Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 13
Default Defining a Range using Variables

This is VBA 101 for me so your help is very much appreciated.

The problem lies in the syntax between the parenthesis in defining a Range.

OK, so an area between A3 and D30 is coded as Range("A3:D30").Select

Assume that the range is defined by one cell only: If A3 is located by
trapping the last row in column A by using a Variable, the code is Range("A"
& VarX).Select (No problem there.)

Now, assume that the range is defined by A3 and any row in column D: if D30
is located by trapping the last row in column D by using a Variable, the
area is defined as Range("A3:D" & VarY).Select (No problem there.)

The Big Question is: How do to code an area defined by using two Variables?
Given the area is defined by A(VarY) down to D(VarX), the code Range("A"&
Var ":D" & VarY).Select does not work. What is the correct syntax in this
case?

(Assume that both variables have been properly "Dimm"ed and executed.)






  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,058
Default Defining a Range using Variables

Check your typing. Your syntax is O.K.

Sub billy()
VarY = 2
VarX = 7
Range("A" & VarY & ":D" & VarX).Select
End Sub
--
Gary''s Student - gsnu200817
  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,346
Default Defining a Range using Variables

Hi,

Your basic idea is fine you just lost an &:

Range("A" & Var & ":D" & VarY)

If this helps, please click the Yes button

Cheers,
Shane Devenshire

"Billyruben" wrote:

This is VBA 101 for me so your help is very much appreciated.

The problem lies in the syntax between the parenthesis in defining a Range.

OK, so an area between A3 and D30 is coded as Range("A3:D30").Select

Assume that the range is defined by one cell only: If A3 is located by
trapping the last row in column A by using a Variable, the code is Range("A"
& VarX).Select (No problem there.)

Now, assume that the range is defined by A3 and any row in column D: if D30
is located by trapping the last row in column D by using a Variable, the
area is defined as Range("A3:D" & VarY).Select (No problem there.)

The Big Question is: How do to code an area defined by using two Variables?
Given the area is defined by A(VarY) down to D(VarX), the code Range("A"&
Var ":D" & VarY).Select does not work. What is the correct syntax in this
case?

(Assume that both variables have been properly "Dimm"ed and executed.)






  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Defining a Range using Variables

Another one:

With activesheet
.range(.cells(vary,"A"),.cells(varx,"D")).select
end with



Billyruben wrote:

This is VBA 101 for me so your help is very much appreciated.

The problem lies in the syntax between the parenthesis in defining a Range.

OK, so an area between A3 and D30 is coded as Range("A3:D30").Select

Assume that the range is defined by one cell only: If A3 is located by
trapping the last row in column A by using a Variable, the code is Range("A"
& VarX).Select (No problem there.)

Now, assume that the range is defined by A3 and any row in column D: if D30
is located by trapping the last row in column D by using a Variable, the
area is defined as Range("A3:D" & VarY).Select (No problem there.)

The Big Question is: How do to code an area defined by using two Variables?
Given the area is defined by A(VarY) down to D(VarX), the code Range("A"&
Var ":D" & VarY).Select does not work. What is the correct syntax in this
case?

(Assume that both variables have been properly "Dimm"ed and executed.)


--

Dave Peterson
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
Defining Range Name anshu[_2_] Excel Discussion (Misc queries) 2 July 22nd 07 07:30 AM
Defining Variables with Same Name in Different Worksheets mhyzak Excel Discussion (Misc queries) 1 May 3rd 07 10:25 PM
VBA defining variables Jeff Excel Discussion (Misc queries) 2 November 3rd 05 11:33 PM
solver and defining all variables different than one another excel_excel_excel Excel Discussion (Misc queries) 0 July 19th 05 07:38 AM
Defining a range Don Excel Worksheet Functions 1 February 25th 05 03:54 PM


All times are GMT +1. The time now is 07:26 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"