Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Variable Acting Like a Constant?

I have a problem with this statement: myrow =
Range("A1").CurrentRegion.Rows.Count + 1,
or as an alternative myrow = Range("A1").End(xlDown).Row + 1, when the
number of rows of data on a worksheet changes. My goal, using this
variable, is to determine the row number of the line just below the last
line of data.

Assume a worksheet with 10 rows of data with cell A1 included in the first
row of data. myrow = 11, and both of the two expressions just mentioned
will also evaluate to 11. That's great so far.

Assume later in the procedure some code adds 10 more rows of data starting
at row 11, increasing the total number of rows of data to 20. At this point
I have found that myrow still equals 11 while either of the two expressions
now evaluate to 21, the correct number. If subsequently, more rows of data
are added, the value of myrow remains constant at 11 while
Range("A1").CurrentRegion.Rows.Count or Range("A1").End(xlDown).Row + 1
will evaluate again to the correct number.

Why is the variable myrow acting like a constant? Note in my declarations I
did not precede myrow with "Const". How can I get myrow to act like a
variable?

Thanks.


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Variable Acting Like a Constant?

You have to execute the code that sets myRow again whenever the data
changes, or more appropriately, just prior to the code that uses that
variable.

Variables are not event driven, that is they do not update when whatever
they refer to changes.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"George Boynton" wrote in message
...
I have a problem with this statement: myrow =
Range("A1").CurrentRegion.Rows.Count + 1,
or as an alternative myrow = Range("A1").End(xlDown).Row + 1, when the
number of rows of data on a worksheet changes. My goal, using this
variable, is to determine the row number of the line just below the last
line of data.

Assume a worksheet with 10 rows of data with cell A1 included in the first
row of data. myrow = 11, and both of the two expressions just mentioned
will also evaluate to 11. That's great so far.

Assume later in the procedure some code adds 10 more rows of data

starting
at row 11, increasing the total number of rows of data to 20. At this

point
I have found that myrow still equals 11 while either of the two

expressions
now evaluate to 21, the correct number. If subsequently, more rows of

data
are added, the value of myrow remains constant at 11 while
Range("A1").CurrentRegion.Rows.Count or Range("A1").End(xlDown).Row + 1
will evaluate again to the correct number.

Why is the variable myrow acting like a constant? Note in my declarations

I
did not precede myrow with "Const". How can I get myrow to act like a
variable?

Thanks.




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 106
Default Variable Acting Like a Constant?

You could be able to get away with something like that if you could code it
in a cell, name the cell and use that name as a variable or as
RANGE("name").Value in VBA. That way Excel would recalculate the cell's
formula and produce a new result whenever something changes.

=ROWS(rangename)

could be what you need IF in your code you make sure that "rangename"
expands whenever you add a line in your worksheet.
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
how can we make one constant number to be act as variable Vimlesh Excel Discussion (Misc queries) 3 June 1st 10 11:26 PM
Count with 1 variable & 1 constant criteria formula Excel-User-RR Excel Worksheet Functions 3 February 3rd 09 05:54 PM
Stopping a constant variable cell from being copied. Link New Users to Excel 3 May 15th 07 03:35 AM
How to average one constant # to variable #s? A1:A2 A1:A3 A1:A4 Colfax Excel Worksheet Functions 1 March 2nd 06 02:49 AM
How to declare variable as Excel constant? John Wirt[_6_] Excel Programming 2 August 22nd 04 05:41 PM


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