Short VBA Code Help

pomereng

New Member
Joined
Aug 28, 2014
Messages
4
I have a list of dates in column M that I already have sorted from earliest date on. I'm trying to create a macro that will look from M2 to the last cell used in column M and If it finds the specific date/s, to copy the row, then offset it below the data by 2 rows, and paste the row.

This is what I have so far, obviously it's not working as I have never used "For Each" loops or If-Then Codes before.

Sub DateRng()
'
' DateRng Macro
'


'
Dim oscar As Date


oscar = CDate(mm / dd / yyyy)


For Each oscar In Sheets(D186).Range("M2", & Rows.Count)
If oscar.Date = "11/23/2009" Then
ActiveRow.Select
Selection.Copy

Range("A1").End(xlDown).Offset(2, 0).Select
ActiveSheet.Paste
End If
Next


End Sub
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
This may work, but I'm not sure as I do not know the date format your worksheet is using. Also, is your sheet called D186? If so, it should be inside speach-marks, i.e. Sheets("D186")
Code:
Sub DateRng()

' DateRng Macro

Dim rng As Range

Application.ScreenUpdating = False

For Each rng In Sheets(D186).Range("M2:M" & Rows.Count)
    If rng.Value = "11/23/2009" Then
        rng.EntireRow.Copy
        Range("A" & Rows.Count).End(xlUp).Offset(2).Paste
    End If
Next rng

With Application
    .ScreenUpdating = True
    .CutCopyMode = False
End With

End Sub
 
Upvote 0

Forum statistics

Threads
1,214,945
Messages
6,122,395
Members
449,081
Latest member
JAMES KECULAH

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