+ Reply to Thread
Results 1 to 10 of 10

Error in Displaying data fetched from a table

  1. #1
    Registered User
    Join Date
    03-30-2013
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    24

    Post Error in Displaying data fetched from a table

    Hi Guys,

    I am facing issues while displaying data fetched from an excel table. The data is fetched dynamically through a loop and I want them to be displayed in other table in the same workbook. The code snippet is mentioned below:

    Please Login or Register  to view this content.
    ****************

    The AGE_INSIGHT is the table from where I am fetching the data based on some Scenario ID's.

    But currently only the last Scenario Id present in the recordset is getting displayed in the output. i.e say if scenario id's IN0000001 and IN000002 are selected then the data of IN000002 is only displayed in the output.

    All the excel guru's out here please help.
    Last edited by Leith Ross; 04-28-2013 at 01:45 PM. Reason: Added Code Tags

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Error in Displaying data fetched from a table

    You seem to copy all the records to the same ActiveCell which overwrites the previous copies.

    ActiveCell.CopyFromRecordset rs

    Offset from the ActiveCell after each copy.

  3. #3
    Registered User
    Join Date
    03-30-2013
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    24

    Re: Error in Displaying data fetched from a table

    Hi AlphaFrog,

    Thanks for your response but can you elaborate a little bit what actually you are trying to refer when you say offset from the ActiveCell.

    Regards
    Basu

  4. #4
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Error in Displaying data fetched from a table

    Replace this...
    ActiveCell.CopyFromRecordset rs

    ...with this if you copy only one row for each ID
    Range("A" & i +1 ).CopyFromRecordset rs

    ...or this if you copy more than one row for each ID
    Range("A" & Rows.Count).End(xlUp).Offset(1).CopyFromRecordset rs
    Last edited by AlphaFrog; 04-28-2013 at 01:24 PM. Reason: changed A1 to Range("A" & Rows.Count)

  5. #5
    Registered User
    Join Date
    03-30-2013
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    24

    Re: Error in Displaying data fetched from a table

    Hi AlphaFrog,

    Actually, the code snippet you wanted me to replace is not fetching the data into the new worksheet "Insight_records" but pasting it into the same sheet where I have the control for these.

    I am also attaching the Sheet which I am trying to update. May be this can give you a better idea of what I am trying to achieve.

    Regards
    Basu

  6. #6
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Error in Displaying data fetched from a table

    Replace this...
    ActiveCell.CopyFromRecordset rs

    ...with this if you copy only one row for each ID
    Sheets("Insight_records").Range("A" & i +1 ).CopyFromRecordset rs

    ...or this if you copy more than one row for each ID
    Sheets("Insight_records").Range("A" & Rows.Count).End(xlUp).Offset(1).CopyFromRecordset rs

  7. #7
    Registered User
    Join Date
    03-30-2013
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    24

    Re: Error in Displaying data fetched from a table

    Hi,

    Please find the attachment.
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    03-30-2013
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    24

    Re: Error in Displaying data fetched from a table

    Hi AlphaFrog,

    Thanks a lot. It works now and it works absolutely fine ... but just one more problem .

    The new sheet being created, is not having the header similar to the AGE_INSIGHT table. Actually I want the fields headers also to be populated along with the data.

    Appreciate if you can help me with this one as well.

    Regards
    Basu

  9. #9
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Error in Displaying data fetched from a table

    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    03-30-2013
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    24

    Re: Error in Displaying data fetched from a table

    Thanks a ton.

    The code works perfectly fine now as I wanted.

+ 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