Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 139
Default Range's Address: How To Change via VBA?

This works, no problem:
-------------------------------------------
?Range("Fund0_MarketTotSEI_Owned").Address
$G$31
-------------------------------------------


But this fails with "Assignment To constant
not permitted" (A compile-time error....)
-------------------------------------------
Range("Fund0_MarketTotSEI_Owned").Address="$G$32"
-------------------------------------------


My agenda is that I'm creating a spreadsheet via VBA in an MS
Access app and one of the columns is a percent computed by
dividing a current row value by a grand total value - and, of
course, we don't know the grand total's value (or row number)
until we've created all the line items.

I can't just run a query to compute said total because part of
the spreadsheet is a "WhatIf" section and the total will change
each time the user does something in that section.

My first thought was to create a range name that points to
somewhere arbitrary, include said name in the .Formulas as I
populate rows, and then alter the range's .Address to point to
the actual total once I know what row it is on.

Is my basic strategy sound?

If so, how to alter that range's .Address? Tried a couple of
Googles, but got overwhelmed by the volume of non-applicable
information returned.

If the strategy is not sound, can anybody suggest something
better?
--
PeteCresswell
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 225
Default Range's Address: How To Change via VBA?

This can be a bit confusing - despite the terminology a
"Named Range" is (in the Excel Object Model) really a
Name object that refers to a Range, rather than a
Range object that happens to have a Name...
(And I doubt that that last sentence removes much
of the confusion..)

Anyway, you need to change the Range that Name
object refers to:

Names("Fund0_MarketTotSEI_Owned").RefersTo = "=$G$32"






On Jul 25, 3:28 pm, "(PeteCresswell)" wrote:
This works, no problem:
-------------------------------------------
?Range("Fund0_MarketTotSEI_Owned").Address
$G$31
-------------------------------------------

But this fails with "Assignment To constant
not permitted" (A compile-time error....)
-------------------------------------------
Range("Fund0_MarketTotSEI_Owned").Address="$G$32"
-------------------------------------------

My agenda is that I'm creating a spreadsheet via VBA in an MS
Access app and one of the columns is a percent computed by
dividing a current row value by a grand total value - and, of
course, we don't know the grand total's value (or row number)
until we've created all the line items.

I can't just run a query to compute said total because part of
the spreadsheet is a "WhatIf" section and the total will change
each time the user does something in that section.

My first thought was to create a range name that points to
somewhere arbitrary, include said name in the .Formulas as I
populate rows, and then alter the range's .Address to point to
the actual total once I know what row it is on.

Is my basic strategy sound?

If so, how to alter that range's .Address? Tried a couple of
Googles, but got overwhelmed by the volume of non-applicable
information returned.

If the strategy is not sound, can anybody suggest something
better?
--
PeteCresswell



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,124
Default Range's Address: How To Change via VBA?

If you want to name a range

range("g32").name="Pete"

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"(PeteCresswell)" wrote in message
...
This works, no problem:
-------------------------------------------
?Range("Fund0_MarketTotSEI_Owned").Address
$G$31
-------------------------------------------


But this fails with "Assignment To constant
not permitted" (A compile-time error....)
-------------------------------------------
Range("Fund0_MarketTotSEI_Owned").Address="$G$32"
-------------------------------------------


My agenda is that I'm creating a spreadsheet via VBA in an MS
Access app and one of the columns is a percent computed by
dividing a current row value by a grand total value - and, of
course, we don't know the grand total's value (or row number)
until we've created all the line items.

I can't just run a query to compute said total because part of
the spreadsheet is a "WhatIf" section and the total will change
each time the user does something in that section.

My first thought was to create a range name that points to
somewhere arbitrary, include said name in the .Formulas as I
populate rows, and then alter the range's .Address to point to
the actual total once I know what row it is on.

Is my basic strategy sound?

If so, how to alter that range's .Address? Tried a couple of
Googles, but got overwhelmed by the volume of non-applicable
information returned.

If the strategy is not sound, can anybody suggest something
better?
--
PeteCresswell


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 139
Default Range's Address: How To Change via VBA?

Per Don Guillett:


Thanks Andrew.

Thanks Don.

I'm on it!!!! -)
--
PeteCresswell
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 do I avoid excel change absolute address to relative address Miguel Excel Discussion (Misc queries) 3 May 10th 07 11:18 PM
questions regarding range's trav Excel Discussion (Misc queries) 3 February 24th 06 06:06 PM
questions regarding range's trav Excel Discussion (Misc queries) 0 February 23rd 06 11:01 PM
Range's comment text Mircea Pleteriu Excel Programming 0 January 20th 05 10:36 AM
Application or Object Defined Error when trying to change a Range's text Wes Lee Excel Programming 2 September 19th 03 06:39 PM


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