+ Reply to Thread
Results 1 to 2 of 2

Find date, copy row above, multiple worksheets

Hybrid View

  1. #1
    Registered User
    Join Date
    09-21-2012
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    21

    Find date, copy row above, multiple worksheets

    [SOLVED]

    Hi all,

    I posted on this recently and thought we came to a solution, but it does not seem to be working. I have a variable called "mmonth" that is the date. The dates, in identical formats, are listed in column A of various worksheets. I have a code that searches through a worksheet and finds the date, then copies the row above it to the current row, and renames the cell in column A back to the current date.

    Sheets("Sheet1").Select
    Cells.Find(What:=mmonth, After:=ActiveCell, LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False).Activate
    ActiveCell.Offset(-1, 0).EntireRow.Copy Destination:=ActiveCell
    Sheets("Inputs").Range("A4").Copy Destination:=ActiveCell
    When I try the same code after it with a Sheet2 replacing Sheet1, the error I receive tells me that the sheet is out of range. This macro is contained in "Module 1," so it should work for the entire workbook.

    The same error comes when I try this code, which was suggested by another user on this site:

    Dim FoundIt As Range
        
                Set FoundIt = Sheets("Sheet2").Cells.Find(What:=mmonth, After:=ActiveCell, _
                                                         LookIn:=xlFormulas, LookAt:=xlPart, _
                                                         SearchOrder:=xlByRows, SearchDirection:=xlNext, _
                                                         MatchCase:=False, SearchFormat:=False)
            
                    If Not FoundIt Is Nothing Then
                        FoundIt.Offset(-1, 0).EntireRow.Copy Destination:=FoundIt.EntireRow
                    Else
                        MsgBox "The Date " & mmonth & " was found.", vbExlam + vbOKOnly
                    End If
                
                Sheets("Inputs").Range("A4").Copy Destination:=FoundIt
    Any insight to why this isn't working for sheets2, 3, and 4... would be appreciated.

    Thanks!
    Last edited by DAK266; 10-02-2012 at 10:14 AM.

  2. #2
    Registered User
    Join Date
    09-21-2012
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    21

    Re: Find date, copy row above, multiple worksheets

    [SOLVED]

    I simply renamed the worksheets and it worked. I am not sure why, but it did.

+ 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