Hi,
Im trying to get the unique dates from a range, sorted them in ascending order converting dates into the financial year week (which is based on July to Jun year). Once this is done the result i would like to display in a listbox by concatenating the week number + Week Start Date + Week End date
i able to get to the last bit however the data display in list box is not in the above format.
any help and guidance will be much appreciated. There are two codes one for unique dates and the other one for listing the values in combobox.
Im trying to get the unique dates from a range, sorted them in ascending order converting dates into the financial year week (which is based on July to Jun year). Once this is done the result i would like to display in a listbox by concatenating the week number + Week Start Date + Week End date
i able to get to the last bit however the data display in list box is not in the above format.
any help and guidance will be much appreciated. There are two codes one for unique dates and the other one for listing the values in combobox.
Cell Formulas | ||
---|---|---|
Range | Formula | |
I2 | I2 | =F2 |
J2 | J2 | =MIN(F:F)-WEEKDAY(I2,17)+1 |
K2:K34 | K2 | =IF(J2="","",J2+7-WEEKDAY(J2,17)) |
L2:L34 | L2 | =WEEKNUM(J2-184) |
J3:J34 | J3 | =IF(MAX(F:F)>K2,K2+1,"") |
A9:A10,A5:A6 | A5 | =A4 |
A16:A34,A11:A13,A7:A8 | A7 | =A6+1 |
VBA Code:
Sub Uniques()
Dim oColl As New Collection
Dim nr As Variant
Dim vArr1 As Long
Dim vItem As Variant
Dim j As Long
Application.ScreenUpdating = False
nr = Range("A" & Rows.Count).End(xlUp).Row
vArr = Range("A1:A" & (nr))
On Error Resume Next
'For j = LBound(vArr) To UBound(vArr1)
For j = 1 To nr
oColl.Add vArr(j, 1), CStr(vArr(j, 1))
Next j
On Error GoTo 0
For Each vItem In oColl
X = X + 1
Range("F" & X).Value = vItem
Columns("F:F").Sort key1:=Range("F2"), _
order1:=xlAscending, Header:=xlYes
'Debug.Print vItem
Next vItem
Call ListBox1
Application.ScreenUpdating = True
End Sub
Sub ListBox1()
Dim UnionRange As Range
Dim cell As Range
Dim lr As Variant
Application.ScreenUpdating = False
lr = Columns("j").Find("*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows, LookIn:=xlValues).Row
' use Union to merge as many named ranges you need
'Set UnionRange = Union(Range("Wk_Start"), Range("Wk_End"), Range("Wk_Num"))
Set UnionRange = Union(Range("J1:J" & lr), Range("k1:K" & lr), Range("L1:L" & lr))
Me.ComboBox1.Clear
For Each cell In UnionRange
ComboBox1.AddItem cell.Value
Next cell
ComboBox1.ListIndex = 0
Range("g2").Value = Me.ComboBox1.Text
Application.ScreenUpdating = True
End Sub