Copy and paste entire row to second sheet based on cell value

Cupragsw

New Member
Joined
May 6, 2015
Messages
3
I need to copy data of 6 sheets if the value of col B is the date entered into a message box

So if Col B on sheet "Abs" is 11/5/15 and that was entered into the msgbx it needs to be added to Mergesheet Starting line A2.

it needs to copy all rows of sheet "Abs" that col B = the date entered.

Then move on to sheet "Dave" and do the same and add it to mergesheet underneath the allready copied data.

I would also like to note that the data on sheet Abs Dave .... starts at A6 as the rest is used for the headings
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Here is code according to your specifications....

Code:
Sub GetData()
Dim sh As Worksheet
Dim rF As Range, rD As Range
Dim sFAddr As String
Dim MaxDate As String
Dim sName As Range
Dim sDate As String
Dim lR As Long
    sDate = Application.InputBox("Get data for date...?")
    If sDate = "" Then Exit Sub
    If IsDate(sDate) Then
        Application.ScreenUpdating = False
        Sheets("MergeSheet").Rows("2:" & Rows.Count).Clear
        For Each sh In ThisWorkbook.Worksheets
            If sh.Name <> "MergeSheet" Then
                With sh.UsedRange.Columns("B")
                    Set rF = .Find(What:=CDate(sDate), LookAt:=xlPart, SearchOrder:=xlByRows, _
                                   SearchDirection:=xlNext, MatchCase:=False)
                    If Not rF Is Nothing Then
                        sFAddr = rF.Address
                        Do
                        'Actionable code goes between these lines
                        '=========================================
                            lR = Sheets("MergeSheet").Range("A" & Rows.Count).End(xlUp).Offset(1).Row
                            rF.EntireRow.Copy Destination:=Sheets("MergeSheet").Cells(lR, 1)
                        '=========================================
                            Set rF = .FindNext(After:=rF)
                        Loop While Not rF Is Nothing And rF.Address <> sFAddr
                    End If
                End With
            End If
        Next sh
    Else
        MsgBox "The date you entered was not valid!", vbExclamation
    End If
    Application.ScreenUpdating = True
    MsgBox "All matching dates have been collected onto the MergeSheet!", vbInformation
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,756
Members
448,990
Latest member
Buzzlightyear

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top