Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default VB Syntax for OFFSET statement

Hi, I have defined a name in a worksheet to refer to a number. For
example the name "rows" refers to 3. How can I use the name within an
OFFSET statement in a VB macro? I have tried different forms of
OFFSET("rows",7) or OFFSET("=rows",7), or OFFSET(range("rows"),7), etc.
Nothing seems to work.

Can someone please help me with this? Many thanks.

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default VB Syntax for OFFSET statement


Jake Marx wrote:
Hi Bathan,

wrote:
Range("$A$1").Offset(Range("rows").value,0).Select

and got the error message:

Run-time error '1004'
Method 'Range' of object '_Global' failed.

What did I do wrong? many thanks


There are a few things you could try to rectify this. Try each step below
to see if one will work for you:

1) If you're using a button to launch the code, make sure the
TakeFocusOnClick property of the CommandButton is set to False.

2) Ensure that the "rows" named range has an integer value of = 0. From
the Immediate Window:

?Range("rows").Value

3) Does this command give you the correct cell reference:

?Range("$A$1").Offset(Range("rows").value,0).Addre ss

If so, then the Select is failing because you're trying to select a Range on
an inactive Worksheet. I don't think this is the problem, as the error
indicates a problem with the Range itself, not the selection. That said, if
you can remove the .Select, you should. Most things in Excel can be done
without activating or selecting anything.

4) Try fully-qualifying your Range reference:

Sheets("Sheet1").Range("$A$1").Offset(Range("rows" ).value,0).Select


Thanks for replying, Jake. I should point out that if I write the
statement:

Range("$A$1").Offset(3,0).Select,

the macro works fine. Only when I substitue Range("rows") for 3 as the
first argument of Offset do I get the error message. Does this give
some indication of where the problem is? Thanks again for all your
help.

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
if statement syntax help OfficeManager Excel Worksheet Functions 6 July 23rd 08 08:09 PM
need help with syntax of if statement Melody Excel Worksheet Functions 3 February 15th 08 05:05 PM
VB Excel syntax for "offset" statement [email protected] Excel Programming 4 July 14th 06 04:16 PM
Excel97 - Syntax for Find, Offset, Insert Page djh Excel Programming 2 October 5th 05 02:36 PM
OFFSET Syntax Scott1523[_2_] Excel Programming 2 August 5th 04 04:33 PM


All times are GMT +1. The time now is 03:54 AM.

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

About Us

"It's about Microsoft Excel"