+ Reply to Thread
Results 1 to 13 of 13

Copying cells based on date.

  1. #1
    Registered User
    Join Date
    08-08-2011
    Location
    Warwick
    MS-Off Ver
    Excel 2003
    Posts
    48

    Copying cells based on date.

    Hi Team,

    I'm looking for some help in copying some data from one sheet to another based on the condition of dates - I've attached an example worksheet


    Basically what I'm looking to do is take the date value in Sheet2 - B3, search through Sheet1 - Column B until there is a match. When there is a match copy the values on the same line in Columns E&F into the relevant cells in Sheet 2.

    Basically copy the Prices in USD and GBP from sheet 1 to sheet 2 where the dates line up!

    Sorry if my explanation is either long-winded or just rubbish!!

    Thanks in advance,


    - Jon
    Attached Files Attached Files
    Last edited by JonathanMoore; 11-16-2011 at 07:22 AM.

  2. #2
    Valued Forum Contributor Steffen Thomsen's Avatar
    Join Date
    10-15-2010
    Location
    Kolding, Denmark
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    953

    Re: Copying cells based on date.

    Hi,

    You can use this:

    Please Login or Register  to view this content.
    Steffen Thomsen

  3. #3
    Registered User
    Join Date
    08-08-2011
    Location
    Warwick
    MS-Off Ver
    Excel 2003
    Posts
    48

    Re: Copying cells based on date.

    Hi Steffen,

    That code works nicely thanks

    However, when I move the code into the actual worksheet (I couldn't upload it as it contains company data) it throws up an error:

    Object variable or With block variable not set"
    I've modifed the code so that "Sheets1" and "Sheets2" are the correct names, have I missed anything?

    Thanks again for your help!


    - Jon

  4. #4
    Valued Forum Contributor Steffen Thomsen's Avatar
    Join Date
    10-15-2010
    Location
    Kolding, Denmark
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    953

    Re: Copying cells based on date.

    Where have you placed the code?

    In the sheet module or in a new module?
    Do you have any hidden rows/colums in the sheet?

  5. #5
    Registered User
    Join Date
    08-08-2011
    Location
    Warwick
    MS-Off Ver
    Excel 2003
    Posts
    48

    Re: Copying cells based on date.

    It's in a new module with no other code in it and there are no hidden rows or columns.

    I'm using the actual name of the sheet, i.e. Sheets("SBL Fax") rather than Sheets(1) - could this be the issue?

    Thanks,

  6. #6
    Valued Forum Contributor Steffen Thomsen's Avatar
    Join Date
    10-15-2010
    Location
    Kolding, Denmark
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    953

    Re: Copying cells based on date.

    Try with the sheets(1) instead

  7. #7
    Registered User
    Join Date
    08-08-2011
    Location
    Warwick
    MS-Off Ver
    Excel 2003
    Posts
    48

    Re: Copying cells based on date.

    New error

    Type Mismatch
    at this line:

    findStr = CDate(Sheets(17).Range("B3"))

  8. #8
    Valued Forum Contributor Steffen Thomsen's Avatar
    Join Date
    10-15-2010
    Location
    Kolding, Denmark
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    953

    Re: Copying cells based on date.

    Whats the format of the data stored in that range?

  9. #9
    Registered User
    Join Date
    08-08-2011
    Location
    Warwick
    MS-Off Ver
    Excel 2003
    Posts
    48

    Re: Copying cells based on date.

    Sheet(17) cell B3 is calculated using this formula:
    Please Login or Register  to view this content.
    And the cell format is:

    *dd/mm/yyyy

    This is the same as the dates in Sheet(18) that it is compared to

  10. #10
    Valued Forum Contributor Steffen Thomsen's Avatar
    Join Date
    10-15-2010
    Location
    Kolding, Denmark
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    953

    Re: Copying cells based on date.

    And its the right sheetindex?

    Sheets(1) refers to the first sheet in the workbook, not neceseraly the sheet witn name Sheet1

    In the same way Sheets(17) refers to number 17 worksheet from the left.

  11. #11
    Registered User
    Join Date
    08-08-2011
    Location
    Warwick
    MS-Off Ver
    Excel 2003
    Posts
    48

    Re: Copying cells based on date.

    Yeah - looking at the way that they're listed within the VB editor, the two sheets i need are named as follows:

    Sheet17 (SBL Fax)
    Sheet18 (SBL Ex TDG)

    But when I count along the sheets from left to right within excel I get the following

    SBL Fax = Sheet11
    SBL Ex TDG = Sheet12

    If I try and use 11 & 12 within the macro - i get the "Object Variable not set" error again.

  12. #12
    Valued Forum Contributor Steffen Thomsen's Avatar
    Join Date
    10-15-2010
    Location
    Kolding, Denmark
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    953

    Re: Copying cells based on date.

    Try declaring the variables

    Please Login or Register  to view this content.

  13. #13
    Registered User
    Join Date
    08-08-2011
    Location
    Warwick
    MS-Off Ver
    Excel 2003
    Posts
    48

    Re: Copying cells based on date.

    That's worked brilliantly

    Thanks for your help!


    - Jon

+ 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