VBA Macro

pomereng

New Member
Joined
Aug 28, 2014
Messages
4
I am working on a macro and VBA Coding and am in need of some help.

The code I have so far, which works, is
Rows(2).Select
Selection.Copy

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

Pretty self explanatory: Selects Row 2, Copies, Offsets after last filled cell in column A by 2 rows, then pastes.

Now, column M on my worksheet has a list of Dates. I have this sorted from oldest to newest. What I want to happen, is for the macro to look at the Dates in column M and if it is equal to the Date in cell M2, the oldest date and because row 1 has a header, then I want to select those rows, then offset paste them as done in with the code above.
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Code:
[color=darkblue]Sub[/color] Copy_Oldest()
    [color=darkblue]Dim[/color] rngOld [color=darkblue]As[/color] Range
    Application.ScreenUpdating = [color=darkblue]False[/color]
    Range("M:M").AutoFilter 1, Range("M2").Value
    [color=darkblue]Set[/color] rngOld = Range("M2", Range("M" & Rows.Count).End(xlUp)).EntireRow
    ActiveSheet.AutoFilterMode = [color=darkblue]False[/color]
    rngOld.Copy Destination:=Range("A" & Rows.Count).End(xlUp).Offset(2)
    Application.ScreenUpdating = [color=darkblue]True[/color]
[color=darkblue]End[/color] [color=darkblue]Sub[/color]
 
Upvote 0

Forum statistics

Threads
1,214,915
Messages
6,122,212
Members
449,074
Latest member
cancansova

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