Hi,
Any ideas how can i get cell address values of EACH dates which are displayed in a range which are in Sheet1
Structure of sheet1
<tbody>
</tbody>
[Structre and code adopted from MrExcel - thread 1088850]
Thanks
NimishK
Any ideas how can i get cell address values of EACH dates which are displayed in a range which are in Sheet1
Structure of sheet1
A | B | C | D | E | F | G | |
1 | abcd | 01-01-2019 | 300 | 02-01-2019 | 400 | 03-01-2019 | 500 |
2 | xyz | 03-01-2019 | 200 | 03-01-2019 | 100 | 05-01-2019 | 150 |
3 | lmnp | 04-01-2019 | 100 | 06-01-2019 | 600 | 07-01-2019 | 700 |
4 | excl | 08-01-2019 | 150 | 08-01-2019 | 0 | 08-01-2019 | 250 |
5 | dfert | 07-01-2019 | 300 | 09-01-2019 | 400 | 10-01-2019 | 200 |
<tbody>
</tbody>
Code:
Sub GetCellAddressofDates()
Dim Dn As Range, rng As Range, Col As Variant
Dim nRng As Range
Dim Dic As Object, Dt As Variant
Dim Q
Col = Array(2, 4, 6)
With Sheets("Sheet1")
Set rng = .Range("A2", .Range("A" & Rows.Count).End(xlUp))
End With
Set Dic = CreateObject("Scripting.Dictionary")
Dic.CompareMode = 1
For Each Dt In Col
Set rng = Range(Cells(1, Dt), Cells(Rows.Count, Dt).End(xlUp))
For Each Dn In rng
If Not Dic.exists(Dn.Value) Then
Set Dic(Dn.Value) = CreateObject("Scripting.Dictionary")
End If
If Not Dic(Dn.Value).exists(Dn.Row) Then
Dic(Dn.Value).Add (Dn.Row), Nothing
End If
Next Dn
Next Dt
Dim k As Variant, nDt As Date, Ldt As Date, p As Variant, c As Long
c = 1
With Sheets("Sheet2")
If txtFromDate.Value <> "" And txtToDate.Value <> "" Then
For Each k In Dic.Keys
If Dic.exists(CDate(txtFromDate.Value)) And Dic.exists(CDate(txtToDate.Value)) Then
If k >= CDate(txtFromDate.Value) And k <= CDate(txtToDate.Value) Then
For Each p In Dic(k)
c = c + 1
.Cells(c, "A") = k
.Cells(c, "B") = p
.Cells(c, "C") = [COLOR=#ff0000][B]'to get cell address of value K which is in Sheet1
[/B][/COLOR] Next p
End If
ElseIf Dic.exists(CDate(txtFromDate.Text)) Then
If k >= CDate(txtFromDate.Text) Then
For Each p In Dic(k)
c = c + 1
.Cells(c, "a") = k
.Cells(c, "b") = p
.Cells(c, "C") = [COLOR=#ff0000][B]'to get cell address of value K[/B]
[/COLOR] Next p
End If
End If
Next k
Thanks
NimishK
Last edited: