Consulting

Results 1 to 4 of 4

Thread: set worksheet error

  1. #1

    set worksheet error

    I am trying to set a worksheet to a cell value for various looping purposes but it is giving me an error everytime I try to run it. Have I written this line incorrectly?






    Set RatesWorksheet = (RatesWorkbook.Sheets("Doc").Range("RateRetrievalTasks")(RatesIndex, 3).Value)


    Thanks

  2. #2
    VBAX Master Aflatoon's Avatar
    Joined
    Sep 2009
    Location
    UK
    Posts
    1,597
    Location
    I don't understand what your code is supposed to do. Are you trying to refer to a worksheet using a name stored in a cell?
    Be as you wish to seem

  3. #3
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    Ride the wind to the sun
    Posts
    2,598
    try

    Set RatesWorksheet = Worksheets(RatesWorkbook.Sheets("Doc").Range("RateRetrievalTasks")(RatesIndex, 3).Value)
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

  4. #4
    VBAX Wizard
    Joined
    Apr 2007
    Posts
    6,881
    Location
    I can never keep too many parens straight

    So I find it easier to debug if I use intermediate variables:

        Dim RatesWorksheetName As String
        RatesWorksheetName = RatesWorkbook.Sheets("Doc").Range("RateRetrievalTasks").Cells(RatesIndex, 3).Value
        Set RatesWorksheet = RatesWorkbook.Sheets(RatesWorksheetName)
    I think that was what were trying to do

    Paul

Posting Permissions

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