Consulting

Results 1 to 4 of 4

Thread: same code does not workon diffrent sheet with same type of data

  1. #1
    Banned VBAX Regular
    Joined
    Apr 2007
    Posts
    26
    Location

    same code does not workon diffrent sheet with same type of data

    i have one excel sheet report1 with 900 records generated on 1st of month .


    then i have report 2 with 1200 records generated on 30 th of month

    I run this query on report 2 it runs sucessfully but not on report1
    .
    str1 = "select * from [sheet2$] where profitctr in (Select pc1 FROM [pc$])"
    If objRecordset.State = 1 Then objRecordset.Close

    objRecordset.Open str1, objConnection, adOpenStatic, adLockOptimistic, adCmdText

    only columns i am concerned with are
    column d
    column bp


    plz help

  2. #2
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    The portion of code you supplied only refers to a STRING which has been given the variable str1, however i would imagine the rest of your code refers to Report 2 (or the sheet number) therefore without specifying Report1 or the sheet number for it it will not run on Report1.

    Regards,
    Simon
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  3. #3
    Banned VBAX Regular
    Joined
    Apr 2007
    Posts
    26
    Location
    sheet2 has data on both the report.
    so there should not be any changes in query right

  4. #4
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    Code will only work (run query) on the sheet that is specified in it, it does not matter to Excel that data from both reports is on Sheet2......the code will have a sheet specified to work with to gather data and it will also have a sheet specified to send the data to.

    The best thing you can do is post all of your code or sample workbook(s) to get the solution you need.

    Remember to remove any sensitive or personal data before posting the workbook(s)

    Regards,
    Simon
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

Posting Permissions

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