Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
gvm gvm is offline
external usenet poster
 
Posts: 38
Default finding the row value of a defined name

I need to set a constant (say Truck, dimensioned as an integer) to the value
of the row number of a cell identified to the macro by a defined name (say
Fleet). How do I do that please?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 88
Default finding the row value of a defined name

You won't be able to set a constant based on the rownumber of a named
range as this may change - which means it can't be constant.

You could set it as a variable:

Dim Truck As Integer
Truck = Range("Fleet").Row

Hope this helps
Rowan

gvm wrote:
I need to set a constant (say Truck, dimensioned as an integer) to the value
of the row number of a cell identified to the macro by a defined name (say
Fleet). How do I do that please?

  #3   Report Post  
Posted to microsoft.public.excel.programming
gvm gvm is offline
external usenet poster
 
Posts: 38
Default finding the row value of a defined name

Thanks Rowan, it works of course.

One final question (for this project anyway), I am using a range term, eg
Range("H14:N18"), where all four row and column references are variables, eg
row1, col1, row2, col2. How do I write these variables into the argument of
Range() please?

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 88
Default finding the row value of a defined name

Did you mean something like this:

Dim row1 As Long
Dim col1 As Integer
row1 = Range("Fleet").Cells(1, 1).Row
col1 = Range("Fleet").Cells(1, 2).Column
'etc

Regards
Rowan

gvm wrote:
Thanks Rowan, it works of course.

One final question (for this project anyway), I am using a range term, eg
Range("H14:N18"), where all four row and column references are variables, eg
row1, col1, row2, col2. How do I write these variables into the argument of
Range() please?

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default finding the row value of a defined name

Dim r1 as long
dim c1 as long
dim r2 as long
dim c2 as long
dim myRng as range

with worksheets("sheet1")
set myrng = .range(.cells(r1,c1),.cells(r2,c2))
end with

(I'd use Long instead of integer.)


gvm wrote:

Thanks Rowan, it works of course.

One final question (for this project anyway), I am using a range term, eg
Range("H14:N18"), where all four row and column references are variables, eg
row1, col1, row2, col2. How do I write these variables into the argument of
Range() please?


--

Dave Peterson


  #6   Report Post  
Posted to microsoft.public.excel.programming
gvm gvm is offline
external usenet poster
 
Posts: 38
Default finding the row value of a defined name

Thanks Rowan and Dave,
Dave's response is close to what need (sorry Rowan I was not clearer in my
question) but I'm not quite there yet. I used Dave's information in the
following way:

Range(.Cells(row1, col1), .Cells(row2, col1 +6)).Select
Selection.ClearContents

and I get a compile error. The term ".cells" is highlighted and the error
message is "invalid or unqualified reference"

Thanks again in anticipation .. Greg
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default finding the row value of a defined name

I had

with worksheets("sheet1")
set myrng = .range(.cells(r1,c1),.cells(r2,c2))
end with

That with/end with is important. It means the things that are prefixed with
dots belong to the previous With statement--in my example, Sheet1.

So you could use:

Range(Cells(row1, col1), Cells(row2, col1 +6)).ClearContents

or include that worksheet to make sure you get the correct sheet.

with worksheets("sheet1")
.Range(.Cells(row1, col1), .Cells(row2, col1 +6)).ClearContents
end with

(No need to select in either case.)

gvm wrote:

Thanks Rowan and Dave,
Dave's response is close to what need (sorry Rowan I was not clearer in my
question) but I'm not quite there yet. I used Dave's information in the
following way:

Range(.Cells(row1, col1), .Cells(row2, col1 +6)).Select
Selection.ClearContents

and I get a compile error. The term ".cells" is highlighted and the error
message is "invalid or unqualified reference"

Thanks again in anticipation .. Greg


--

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
Run-time error '50290': Application-defined or object-defined erro Macro button Excel Discussion (Misc queries) 1 March 12th 09 10:59 AM
Finding files in a folder. Variable not defined error. Ayo Excel Discussion (Misc queries) 1 March 14th 08 01:14 PM
Application-Defined or Object-Defined Error on simple code Fid[_2_] Excel Programming 1 July 21st 05 08:30 PM
Application-Defined or Object-Defined Error on simple code [email protected] Excel Programming 6 February 22nd 05 09:03 PM
Application-defined or object-defined error - missing the basics [email protected] Excel Programming 1 December 28th 04 10:23 PM


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