Hello I'm new and confused.
I have been working on my first VBA programming project for the past 2 weeks and now I'm stumped. The workbook will have data pushed to Sheet1. Depending on the date (yesterday) it would then need to copy and paste yesterday's column to the next available column on the correct month's spreadsheet.
Currently I have the info copy and pasting the active column info to the months spreadsheet but it is using today's date to figure the month.
My dates are in (B2:H2) and Sheet2 - Sheet13 are the months January - December although I have just left them named Sheet2-Sheet3 for simplicity. Once they are pasted to the correct months sheet, the MTD is calculated.
When I try using anything other than Month(Date) to determine the correct spreadsheet to paste to, it fails. I have tried Today - 1, Date - 1 to get yesterday's date but I don't have any reference to the range of dates B2:H2
The code that I need help with is:
If Month(Date) = "1" Then
Columns(ActiveCell.Column).Copy
Sheet2.Range("IV1").End(xlToLeft).Offset(0, 1).PasteSpecial xlPasteValues
ElseIf Month(Date) = "2" Then
Columns(ActiveCell.Column).Copy
Sheet3.Range("IV1").End(xlToLeft).Offset(0, 1).PasteSpecial xlPasteValues
ElseIf Month(Date) = "3" Then
Columns(ActiveCell.Column).Copy
Sheet4.Range("IV1").End(xlToLeft).Offset(0, 1).PasteSpecial xlPasteValues
ElseIf Month(Date) = "4" Then
Columns(ActiveCell.Column).Copy
Sheet5.Range("IV1").End(xlToLeft).Offset(0, 1).PasteSpecial xlPasteValues
ElseIf Month(Date) = "5" Then
Columns(ActiveCell.Column).Copy
Sheet6.Range("IV1").End(xlToLeft).Offset(0, 1).PasteSpecial xlPasteValues
ElseIf Month(Date) = "6" Then
Columns(ActiveCell.Column).Copy
Sheet7.Range("IV1").End(xlToLeft).Offset(0, 1).PasteSpecial xlPasteValues
ElseIf Month(Date) = "7" Then
Columns(ActiveCell.Column).Copy
Sheet8.Range("IV1").End(xlToLeft).Offset(0, 1).PasteSpecial xlPasteValues
ElseIf Month(Date) = "8" Then
Columns(ActiveCell.Column).Copy
Sheet9.Range("IV1").End(xlToLeft).Offset(0, 1).PasteSpecial xlPasteValues
ElseIf Month(Date) = "9" Then
Columns(ActiveCell.Column).Copy
Sheet10.Range("IV1").End(xlToLeft).Offset(0, 1).PasteSpecial xlPasteValues
ElseIf Month(Date) = "10" Then
Columns(ActiveCell.Column).Copy
Sheet11.Range("IV1").End(xlToLeft).Offset(0, 1).PasteSpecial xlPasteValues
ElseIf Month(Date) = "11" Then
Columns(ActiveCell.Column).Copy
Sheet12.Range("IV1").End(xlToLeft).Offset(0, 1).PasteSpecial xlPasteValues
ElseIf Month(Date) = "12" Then
Columns(ActiveCell.Column).Copy
Sheet13.Range("IV1").End(xlToLeft).Offset(0, 1).PasteSpecial xlPasteValues
End If
The beginning code in my workbook is this but I believe I have a lot of useless info there as the cell range for my dates doesn't seem to do anything.
Sub WTDSum()
Dim Worksheets As Object
Dim source As Worksheet
Dim destination As Worksheet
Dim emptyColumn As Long
Dim selectedDate As String
Dim rangeFound As Range
selectedDate = ActiveCell.Value
Set rangeFound = Sheet1.Range("B2:H2")
And I tried to upload my workbook but I'm getting the error "This asset is not currently being used by any content that you have access to."
I'm thrilled that I have the macro running at all but if I could get help with this last piece to have it fully automated it would be a tremendous help.
Thank you!
Bookmarks