Av8tordude
Well-known Member
- Joined
- Oct 13, 2007
- Messages
- 1,075
- Office Version
- 2019
- Platform
- Windows
This code creates a table to be able to chart once created. I would to do two things to allow flexibility....
1. Since is table for months, I would like to create the a table for weeks.
2. Select between two dates.
Can anyone assist.. Thank you kindly
1. Since is table for months, I would like to create the a table for weeks.
2. Select between two dates.
Can anyone assist.. Thank you kindly
Code:
Sub ProfitLoss() Dim dt As Date, c As Range, f As Range
Dim lr1 As Long, lr2 As Long, y As String, m As String
Range("AA2:AE" & Rows.Count).ClearContents
lr1 = Range("D" & Rows.Count).End(xlUp).Row
For Each c In Range("D18", Range("D" & Rows.Count).End(xlUp))
y = Year(c)
m = Month(c)
dt = DateSerial(y, m, 1)
Set f = Range("AA:AA").Find(dt, LookIn:=xlValues, lookat:=xlWhole)
If f Is Nothing Then
lr2 = Range("AA" & Rows.Count).End(xlUp).Row + 1
Range("AA" & lr2).Value = dt
Range("AB" & lr2).Value = Cells(c.Row, "P")
Range("AC" & lr2).Value = Evaluate("=MAX(IF(YEAR(D18:D" & lr1 & ")=" & y & _
",IF(MONTH(D18:D" & lr1 & ")=" & m & ",P18:P" & lr1 & ")))")
Range("AD" & lr2).Value = Evaluate("=MIN(IF(YEAR(D18:D" & lr1 & ")=" & y & _
",IF(MONTH(D18:D" & lr1 & ")=" & m & ",P18:P" & lr1 & ")))")
Range("AE" & lr2).Value = Cells(Evaluate("=MAX(IF(YEAR(D18:D" & lr1 & ")=" & y & _
",IF(MONTH(D18:D" & lr1 & ")=" & m & ",ROW(P18:P" & lr1 & "))))"), "P")
End If
Next
End Sub