Help with VBA Macro

ehenry84

New Member
Joined
Mar 17, 2009
Messages
1
I am writing a macro to Copy a range of cells from one sheet to another sheet matching on date values. The code I have so far is:

Code:
Sub CopyData()
    Dim LDate As String
    Dim LRow As Integer
    Dim LFound As Boolean

    'Retrieve date value to search for
    LDate = Sheets("DD Calculator").Range("AX7").Value
    Sheets("DD Calculator").Select
    'Start at row 1000
    LRow = 1000
    LFound = False
    While LFound = False
      If Cells(LRow, 3) = LDate Then
            'Select values to copy from "Rolling Plan" sheet
            Sheets("DD Calculator").Select
            Range("AW11:AW58").Select
            Selection.Copy
            'Paste onto "Plan" sheet
            Sheets("HDDs").Select
            Cells(LRow, 14).Select
            Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
            False, Transpose:=True
            LFound = True

        'Continue searching
        Else
            LRow = LRow + 1
        End If
    Wend
    
End Sub

I ran it once and it worked properly, now it gives me an error on the section:
Code:
 Else
            LRow = LRow + 1
 End If

I have no idea what the issue is, can anyone help please?

Thank you,
Erik
 
Last edited by a moderator:

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.

Forum statistics

Threads
1,215,742
Messages
6,126,611
Members
449,321
Latest member
syzer

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