Results 1 to 2 of 2

reference column date (yesterday) to get Month(Date) for copy paste

Threaded View

  1. #1
    Registered User
    Join Date
    08-12-2013
    Location
    Kennesaw, Georgia
    MS-Off Ver
    Excel 2003
    Posts
    2

    reference column date (yesterday) to get Month(Date) for copy paste

    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!
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Formula to return a True/False if date equals yesterday's date
    By abbeycrombie in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 12-17-2013, 11:31 AM
  2. Copy latest date of every month from a column in excel 2007
    By rt99 in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 03-07-2013, 11:49 AM
  3. Reference a date, then copy and transpose paste into a date specific location
    By nelmsd in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 02-26-2013, 03:30 PM
  4. Replies: 5
    Last Post: 01-16-2013, 08:42 PM
  5. Check column for yesterday's date
    By daillest319 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-31-2012, 03:13 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1