Copy Data to another sheet.

dr greenthumb

New Member
Joined
Mar 9, 2009
Messages
40
Hi,

I have a macro that will copy data from one sheet to another based on whether it finds a date in 1 row, is it possible to change this macro to look on 3 separate rows?

here is the marco I have:

Code:
Sub CopyDataToPlan()

    Dim LDate As String
    Dim LColumn As Integer
    Dim LFound As Boolean
    
    On Error GoTo Err_Execute
    
    'Retrieve date value to search for
    LDate = Sheets("Rolling Plan").Range("B4").Value
    
    Sheets("Plan").Select
    
    'Start at column B
    LColumn = 2
    LFound = False
    
    While LFound = False
    
        'Encountered blank cell in row 2, terminate search
        If Len(Cells(2, LColumn)) = 0 Then
            MsgBox "No matching date was found."
            Exit Sub
        
        'Found match in row 2
        ElseIf Cells(2, LColumn) = LDate Then
                        
            'Select values to copy from "Rolling Plan" sheet
            Sheets("Rolling Plan").Select
            Range("B5:B9").Select
            Selection.Copy
            
            'Paste onto "Plan" sheet
            Sheets("Plan").Select
            Cells(3, LColumn).Select
            Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
                False, Transpose:=False
        
            LFound = True
            MsgBox "The data has been successfully copied."
            
        'Continue searching
        Else
            LColumn = LColumn + 1
        End If
            
    Wend
    
    On Error GoTo 0
    
    Exit Sub
    
Err_Execute:
    MsgBox "An error occurred."
    
End Sub

Any help much appreciated.

Alec.
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney

Forum statistics

Threads
1,224,561
Messages
6,179,522
Members
452,923
Latest member
JackiG

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