Forum Discussion

cinnamonster8765's avatar
cinnamonster8765
Copper Contributor
Mar 23, 2025

VBA code to copy data to another sheet based on date range

Hello! I am working on tracking spending entries for my budget and am new to VBA coding so I'm not understanding everything I'm seeing online for this. I was to enter in the details for the expense (i.e. amount, date, category, etc.) then assign my macro to a button. When I click the macro, I want the code to identify the date of the transaction and move it to the appropriate month's tab. So, if I bought something on February 25th, I want it moved to the February tab. I don't have a great grasp on how variables work yet (this seems to be part of the solution) so any explanations to go along with the coding would be very helpful! I know how to code a copy paste with formatting on the same sheet and moving it to another sheet, but the identification is what's tripping me up. Thank you in advance!

1 Reply

  • See if this gets you started.

        Dim d As Date
        Dim m As String
        Dim w As Worksheet
         ' D2 is the cell in which you enter the date
        d = Range("D2").Value
        ' Get the full name of the month
        m = MonthName(d)
        ' Refer to the worksheet for that month
        Set w= Worksheets(m)
        ' Copy data to w below
        ...

Resources