|
-
Dec 16th, 2022, 08:31 PM
#1
[RESOLVED] Add full month worth of data to worksheet
I have data for a whole month that looks like this. The data includes all the days in December:

I'd like a macro that would add similar data for January 2023.
The general rule is that when the macro is executed, that if there is existing data, the data for the next month is added, otherwise the current month is added.
-
Dec 17th, 2022, 03:58 AM
#2
Re: Add full month worth of data to worksheet
Haven’t understood your rule.
existing data of what? Current day?
Last edited by Zvoni; Tomorrow at 31:69 PM.
----------------------------------------------------------------------------------------
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------------------
People call me crazy because i'm jumping out of perfectly fine airplanes.
---------------------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad
-
Dec 17th, 2022, 09:28 AM
#3
Re: Add full month worth of data to worksheet
If the worksheet is empty except for the headings in rows 1 and 2, add the Day, Date and Time for all the days in the current month, otherwise add the Day, Date and Time for all the days in the next month.
For example if today's date is December 17th, 2022 and the worksheet is empty except for the headings in rows 1 and 2, add the Day, Date and Time for all the full month of December starting in row 3. Then when the macro is run again skip one row below the existing December data and add the Day, Date and Time for all the days in the January 2023.
-
Dec 17th, 2022, 12:04 PM
#4
Re: Add full month worth of data to worksheet
Just check if A3 is empty.
then it‘s a simple loop with Step 5
Last edited by Zvoni; Tomorrow at 31:69 PM.
----------------------------------------------------------------------------------------
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------------------
People call me crazy because i'm jumping out of perfectly fine airplanes.
---------------------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad
-
Dec 17th, 2022, 12:25 PM
#5
Re: Add full month worth of data to worksheet
It's really not that simple. Things to consider:
- How many days in the month?
- What is the correct Day for the Date?
- How to avoid adding a month 13?
- "Step 5" is problematic for the last week in a month.
-
Dec 18th, 2022, 02:50 AM
#6
Re: Add full month worth of data to worksheet
1) use DateAdd to get „LastDayOfMonth“. search for this. Gazillion examples
2) look at Format-Function. Or was it „weekday“? *hint*
3) use DateAdd
4) it‘s not. The step 5 is for the block of rows. And don‘t use a For-Loop
Last edited by Zvoni; Tomorrow at 31:69 PM.
----------------------------------------------------------------------------------------
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------------------
People call me crazy because i'm jumping out of perfectly fine airplanes.
---------------------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad
-
Dec 18th, 2022, 09:49 AM
#7
Addicted Member
Re: Add full month worth of data to worksheet
This seems straightforward. The only thing that seems to be changing is the day of the month - for which a simple loop would work. Date column and day of week column have the same values - you just change the formatting (D-MMM-YY v DDD). And you can get the days of the month through the EOMONTH function:
Code:
Function DaysInMonth(ByVal MonthValue As Long, Optional YearValue As Long = -1)
If YearValue = -1 Then YearValue = Year(Now)
DaysInMonth = Day(WorksheetFunction.EoMonth(DateSerial(YearValue, MonthValue, 1), 0))
End Function
-
Dec 18th, 2022, 10:15 AM
#8
Re: Add full month worth of data to worksheet
Thanks all. I worked it out.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|