Consulting

Results 1 to 7 of 7

Thread: Syntax issue

  1. #1
    VBAX Newbie
    Joined
    Sep 2023
    Posts
    2
    Location

    Syntax issue

    I am rather new to VB and I am trying unsuccessfully to combine two formulas into one.

    Rows(5).Select ------ This formula lets me select row 5 of the current worksheet

    ‘data’!G11 ------ Cell G11 in the data worksheet is the one I want to substitute for row 5

    Rows(‘data’!G11). ------ Select this is sort of what I am after but I cant seem to find the correct syntax to incorporate the cell into the formula. I am using it in a useform.

    Any help would be appreciated.

  2. #2
    VBAX Mentor
    Joined
    Nov 2022
    Location
    The Great Land
    Posts
    337
    Location
    Don't use smart apostrophes or quotes (aka tilted apostrophe/quote) in code.

    You want value from cell G11?

    It usually is not necessary to actually "Select" anything when manipulating Excel.

    Is "data" the sheet name?

    Rows(Worksheets("data").Range("G11")).Select

    What are you trying to accomplish?
    How to attach file: Reading and Posting Messages (vbaexpress.com), click Go Advanced below post edit window. To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,059
    Location
    Welcome to VBAX John R. As June7 has suggested the format needs to be
    Rows(Worksheets("data").Range("G11")
    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

  4. #4
    VBAX Mentor
    Joined
    Nov 2022
    Location
    The Great Land
    Posts
    337
    Location
    Aussie, missing closing parenthesis
    How to attach file: Reading and Posting Messages (vbaexpress.com), click Go Advanced below post edit window. To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,059
    Location
    A swing and a miss......about my standard
    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

  6. #6
    VBAX Newbie
    Joined
    Sep 2023
    Posts
    2
    Location
    I was trying to select a specific row to copy it. I worked around the issue by putting using a variable and putting that into the script instead. Your format looks much cleaner, I am going to convert it over to your method. Thanks!!!

  7. #7
    VBAX Mentor
    Joined
    Nov 2022
    Location
    The Great Land
    Posts
    337
    Location
    Again, it is not necessary to actually "Select" to copy or get values.

    Review https://stackoverflow.com/questions/...heet-vba-excel


    Another method of copying data to another sheet:

    xlApp.Worksheets("Sheet1").Range("A1:AM900").Value = Worksheets("Results").Range("A2:AM900").Value
    How to attach file: Reading and Posting Messages (vbaexpress.com), click Go Advanced below post edit window. To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Posting Permissions

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