Using VBA to break out a whole month even if zero data

RomoBot

New Member
Joined
Oct 25, 2021
Messages
14
Office Version
  1. 365
Platform
  1. MacOS
Hello, this to me feels a bit complicated but I'm hoping to find an elegant solution. I am new to posting here so please let me know what all additional information I need to provide if I am missing something. Also as a caveat, I am very rudimentary at VBA - I basically know how to copy and paste from what people post as solutions.

I need to track number of posts per day, even if they are zero, based on a downloaded CSV file in a specific format (only including days there were posts) and also combine dates that are the same.

Basically: I need to turn this:

1635205319662.png


Into this:

1635205341473.png


Using a macro that can also recognize the length of the month (not always July.) It also has to all be done as a macro, because I am turning it over to the client who wants to just paste the raw data and have (the second picture) appear.

Any help would be much appreciated!
 

Attachments

  • 1635205201621.png
    1635205201621.png
    23.9 KB · Views: 9
it would be better to change it to :
VBA Code:
Sub Macro3()
    Dim Lr As Long, i As Long, C As Long, M As Long
    Range("G1:I1").Value = Array("Date", "# of Posts", "Engagements")
    Lr = Range("A" & Rows.Count).End(xlUp).Row
    Range("G2").Value = Application.WorksheetFunction.EoMonth(Application.WorksheetFunction.Min(Range("A2:A" & Lr)), -1) + 1
    C = Application.WorksheetFunction.EoMonth(Application.WorksheetFunction.Max(Range("A2:A" & Lr)), 0) - Range("G2").Value + 1
    Range("G2").EntireColumn.NumberFormat = "dd-mmm"
    Range("G2").AutoFill Destination:=Range("G2").Resize(C), Type:=xlFillDefault
   
    Range("H2").Formula = "=IF(SUMIFS(B$2:B$" & Lr & ",$A$2:$A$" & Lr & ",$G2)=0,"""",SUMIFS(B$2:B$" & Lr & ",$A$2:$A$" & Lr & ",$G2))"
    Range("I2").Formula = "=IF(SUMIFS(E$2:E$" & Lr & ",$A$2:$A$" & Lr & ",$G2)=0,"""",SUMIFS(E$2:E$" & Lr & ",$A$2:$A$" & Lr & ",$G2))"
    Range("H2:I2").AutoFill Destination:=Range("H2:I" & C + 1), Type:=xlFillDefault
    Range("H2:I" & C + 1).Value = Range("H2:I" & C + 1).Value
End Sub
 
Upvote 0

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.

Forum statistics

Threads
1,214,875
Messages
6,122,039
Members
449,063
Latest member
ak94

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