+ Reply to Thread
Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    07-14-2009
    Location
    Australia
    MS-Off Ver
    Excel 2003
    Posts
    1

    Need help with searching through worksheets and copying/ pasting

    Could anyone please help me with this!??

    I'm currently using excel 2003 and need to write a macro to do the following but i can't figure out how to do it!

    I have a main worksheet in a workbook thats called MonthData and several other worksheets within the workbook for each month. Each worksheet is called after its month and year, eg: Jan 09.

    What i want to do is create a macro where i could type the month and year i want to access in a cell, b2, in the spreadsheet MonthData, and then whatever month and year i would type in, it would search for the corresponding month and year in the workbook and then copy the cells b17:h49 from that worksheet and then paste it into cells b14:h46 of the worksheet MonthData.

    Any help would be greatly appreciated!!!
    Thankyou!!!

  2. #2
    Forum Guru
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    5,032

    Re: Need help with searching through worksheets and copying/ pasting

    Hi

    You don't need a macro to do this - you can use formulas.

    In MonthData!B14 enter the formula
    =OFFSET(INDIRECT($B$2&"!a1"),ROW()+2,COLUMN()-1)
    Copy down / across as required.

    Now when you enter your sheet name in B2, it will bring back the data from that sheet.

    HTH

    rylo

  3. #3
    Valued Forum Contributor
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    2007
    Posts
    873

    Re: Need help with searching through worksheets and copying/ pasting

    Hi excelsi,

    Welcome to the forum.

    If you really need a macro, you could try this:

    Code:
    Sub Macro1()
        
        'If there is no sheet called by the value in _
        cell A2 (change if required) of the activesheet, then...
        On Error Resume Next
        If IsError(Len(ThisWorkbook.Sheets(Range("A2").Value).Name)) = True Then
            '...inform the user so and quit the routinue.
            MsgBox "This is no tab called " & Range("A2").Value & " in this workbook.", vbExclamation, "Data Consolidation Editor"
            Exit Sub
        'Else...
        Else
            'Copy the values from the desired tab and range to the active sheet.
            Sheets(Range("A2").Value).Range("B17:H49").Copy _
                Range("B17")
        End If
        
    End Sub
    HTH

    Robert
    ____________________________________________
    Please ensure you mark your thread as Solved once it is. Click here to see how
    If this post helps, please don't forget to add to our reputation by clicking the blue scale icon in the top right-hand corner of my post

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

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.2.0