Need Help Creating a Macro for Monthly Use

glenyse

New Member
Joined
Jul 12, 2012
Messages
6
I need help creating a macro that will grab information from an new sheet after it is added to the work book and paste it on a master page and sort it according to the account number. This is what I have so far but I need to find out how to make the Macro loop every month with each new sheet created. I’m not sure how to configure the Macro to go to the next empty row and paste the next months information. I’m very new to this so please be patient with me :). I tried to create a test sheet so you can see somewhat what I'm working with. https://docs.google.com/spreadsheet/ccc?key=0Ap3rr5XT7PiZdFhlSE5vU1pIV2paSS05b1Z2Wkg4M3c#gid=2

Here’s what I have so far as for as a code.

Sub Macro1()
'
' Macro1 Macro
'
' Keyboard Shortcut: Ctrl+q
'
Sheets("June 2012").Select
Range("A2:C16").Select
Selection.Copy
Sheets("Master").Select
ActiveSheet.Paste
Range("A17").Select
Sheets("July 2012").Select
Range("A2:C15").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Master").Select
ActiveSheet.Paste
End Sub
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
See if this works. You need to have the select the sheet with the month you want to export and run the macro

Code:
Sub getMaster()

Dim i As Long
Dim iRow As Long
Dim iCurRow As Long




iRow = Sheets("Master").Cells(Rows.Count, 1).End(xlUp).Row
iCurRow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row


With Sheets("Master")


ActiveSheet.Range("A2:A" & iCurRow).Resize(, 3).Copy _
Destination:=.Cells(iRow, 1).Offset(1, 0)
End With


'lets filter


With Worksheets("Master")
    .Range("A1").AutoFilter
    .AutoFilter.Sort.SortFields.Clear
    .AutoFilter.Sort.SortFields.Add Key:=Range _
    ("A1:A" & iRow), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    
    With .AutoFilter.Sort
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
    
    .Range("A1").AutoFilter
    


End With


End Sub
 
Upvote 0
Not sure if this will help or not:


This will add a sheet for the current month
Code:
Dim x As String

x = Format(DateAdd("m", 0, Date), "MMM YYYY")

Sheets.Add.Name = x


This will copy the sheet to the next empty row on sheets Master:

Code:
Dim x As String

x = Format(DateAdd("m", 0, Date), "MMM YYYY")

Sheets(x).Range("A2:C16").Copy Sheets("Master").Range("A" & Rows.Count).End(3)(2)

See if this is along the lines of what you need. I didn't use your test sheet or address the sort issue.
 
Upvote 0

Forum statistics

Threads
1,223,630
Messages
6,173,454
Members
452,514
Latest member
cjkelly15

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