+ Reply to Thread
Results 1 to 6 of 6

syntax when using variables

Hybrid View

NoWhereMan2012 syntax when using variables 07-14-2012, 01:48 PM
Thalassa Re: syntax when using... 07-14-2012, 02:06 PM
NoWhereMan2012 Re: syntax when using... 07-14-2012, 03:54 PM
shg Re: syntax when using... 07-14-2012, 02:09 PM
NoWhereMan2012 Re: syntax when using... 07-14-2012, 03:44 PM
shg Re: syntax when using... 07-14-2012, 05:33 PM
  1. #1
    Registered User
    Join Date
    07-13-2012
    Location
    Stoke UK
    MS-Off Ver
    Excel 2003
    Posts
    15

    syntax when using variables

    I want to select a range of 2 cells when closing form and returning to excel sheet

    if you know the range you use
    Range("J6:K6").Select
    but I don't know what row its going to be so need to use variable b, how do I rewrite this code?

    Tried
    Range("J" & b:"K" & b).Select

  2. #2
    Forum Contributor
    Join Date
    06-07-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    189

    Re: syntax when using variables

    Try

    Range("J" & b & ":K" & b).Select

  3. #3
    Registered User
    Join Date
    07-13-2012
    Location
    Stoke UK
    MS-Off Ver
    Excel 2003
    Posts
    15

    Re: syntax when using variables

    Thanks for reply but didn't work, although it didn't give me error so I guess its possible something else is happening before selection or after?

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: syntax when using variables

    Or

        Dim iRow As Long
    
        iRow = 42
        Rows(iRow).Range("J1:K1").Select
    Entia non sunt multiplicanda sine necessitate

  5. #5
    Registered User
    Join Date
    07-13-2012
    Location
    Stoke UK
    MS-Off Ver
    Excel 2003
    Posts
    15

    Re: syntax when using variables

    Thanks for the reply

    Does iRow have to be Long?
    I want to use the same variable that I am using for my text input which is b as Integer.

    as b already has the value I need I just altered your code to

    Rows(b).Range("J1:K1").Select

    but it didn't work.

  6. #6
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: syntax when using variables

    Yes, the variable should be a Long. Row numbers extend beyond the range of Integer.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1