Consulting

Results 1 to 7 of 7

Thread: Variable

  1. #1
    VBAX Tutor
    Joined
    Dec 2009
    Posts
    295
    Location

    Variable

    hi

    how can i change the range in the row below into a variable

    [VBA] g = Sheets("sheet3").Range("B65536").End(xlUp).row[/VBA]

    thanks

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    With Worksheets("Sheet3")

    g = .Cells(.Rows.Count, "B").End(xlUp).Row
    Set rng = .Range("B1"),Resize(g)
    End With
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Tutor
    Joined
    Dec 2009
    Posts
    295
    Location
    Quote Originally Posted by xld
    [vba]

    With Worksheets("Sheet3")

    g = .Cells(.Rows.Count, "B").End(xlUp).Row
    Set rng = .Range("B1"),Resize(g)
    End With
    [/vba]
    It writs me "syntax error"

    what should i do?

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Sorry, should be

    [vba]

    With Worksheets("Sheet3")

    g = .Cells(.Rows.Count, "B").End(xlUp).Row
    Set rng = .Range("B1").Resize(g)
    End With
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    VBAX Tutor
    Joined
    Dec 2009
    Posts
    295
    Location
    Quote Originally Posted by xld
    Sorry, should be

    [vba]

    With Worksheets("Sheet3")

    g = .Cells(.Rows.Count, "B").End(xlUp).Row
    Set rng = .Range("B1").Resize(g)
    End With
    [/vba]
    how can i write this macro that instead of "B" will be 2 and instead of
    "b1" will be (2 & 1)

  6. #6
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,064
    Location
    Are you changing yet again the substance of a question because you didn't ask the correct question or supply the correct data at the initial post?
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  7. #7
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Check out the Cells notation eg
    [VBA]
    Set rng = Cells(2,1)
    [/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

Posting Permissions

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