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
[TABLE="width: 539"]
<tbody>[TR]
[TD][/TD]
[TD]A[/TD]
[TD] B[/TD]
[TD]C[/TD]
[TD] D[/TD]
[TD]E[/TD]
[TD] F[/TD]
[TD]G[/TD]
[/TR]
[TR]
[TD="align: right"]1[/TD]
[TD]abcd[/TD]
[TD="align: right"]01-01-2019[/TD]
[TD]300[/TD]
[TD="align: right"]02-01-2019[/TD]
[TD]400[/TD]
[TD="align: right"]03-01-2019[/TD]
[TD]500[/TD]
[/TR]
[TR]
[TD="align: right"]2[/TD]
[TD]xyz[/TD]
[TD="align: right"]03-01-2019[/TD]
[TD]200[/TD]
[TD="align: right"]03-01-2019[/TD]
[TD]100[/TD]
[TD="align: right"]05-01-2019[/TD]
[TD]150[/TD]
[/TR]
[TR]
[TD="align: right"]3[/TD]
[TD]lmnp[/TD]
[TD="align: right"]04-01-2019[/TD]
[TD]100[/TD]
[TD="align: right"]06-01-2019[/TD]
[TD]600[/TD]
[TD="align: right"]07-01-2019[/TD]
[TD]700[/TD]
[/TR]
[TR]
[TD="align: right"]4[/TD]
[TD]excl[/TD]
[TD="align: right"]08-01-2019[/TD]
[TD]150[/TD]
[TD="align: right"]08-01-2019[/TD]
[TD]0[/TD]
[TD="align: right"]08-01-2019[/TD]
[TD]250[/TD]
[/TR]
[TR]
[TD="align: right"]5[/TD]
[TD]dfert[/TD]
[TD="align: right"]07-01-2019[/TD]
[TD]300[/TD]
[TD="align: right"]09-01-2019[/TD]
[TD]400[/TD]
[TD="align: right"]10-01-2019[/TD]
[TD]200[/TD]
[/TR]
</tbody>[/TABLE]
[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
[TABLE="width: 539"]
<tbody>[TR]
[TD][/TD]
[TD]A[/TD]
[TD] B[/TD]
[TD]C[/TD]
[TD] D[/TD]
[TD]E[/TD]
[TD] F[/TD]
[TD]G[/TD]
[/TR]
[TR]
[TD="align: right"]1[/TD]
[TD]abcd[/TD]
[TD="align: right"]01-01-2019[/TD]
[TD]300[/TD]
[TD="align: right"]02-01-2019[/TD]
[TD]400[/TD]
[TD="align: right"]03-01-2019[/TD]
[TD]500[/TD]
[/TR]
[TR]
[TD="align: right"]2[/TD]
[TD]xyz[/TD]
[TD="align: right"]03-01-2019[/TD]
[TD]200[/TD]
[TD="align: right"]03-01-2019[/TD]
[TD]100[/TD]
[TD="align: right"]05-01-2019[/TD]
[TD]150[/TD]
[/TR]
[TR]
[TD="align: right"]3[/TD]
[TD]lmnp[/TD]
[TD="align: right"]04-01-2019[/TD]
[TD]100[/TD]
[TD="align: right"]06-01-2019[/TD]
[TD]600[/TD]
[TD="align: right"]07-01-2019[/TD]
[TD]700[/TD]
[/TR]
[TR]
[TD="align: right"]4[/TD]
[TD]excl[/TD]
[TD="align: right"]08-01-2019[/TD]
[TD]150[/TD]
[TD="align: right"]08-01-2019[/TD]
[TD]0[/TD]
[TD="align: right"]08-01-2019[/TD]
[TD]250[/TD]
[/TR]
[TR]
[TD="align: right"]5[/TD]
[TD]dfert[/TD]
[TD="align: right"]07-01-2019[/TD]
[TD]300[/TD]
[TD="align: right"]09-01-2019[/TD]
[TD]400[/TD]
[TD="align: right"]10-01-2019[/TD]
[TD]200[/TD]
[/TR]
</tbody>[/TABLE]
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: