I would really appreciate some help with excel VBA please -
I have 2 data columns on one sheet which also have blanks in between
name Date
a 01-01-2019
c 01-08-2019
b 01-02-2019
f 01-01-2019
. . .
I am trying to display these columns organised in date order, without blanks, on another sheet in the same workbook. eg:
name date
a 01-01-19
f 01-01-19
b 01-02-19
c 01-08-19
I have tried using a For Each loop which contains some If statements, but it is not achieving the desired out come and I think will be very long-winded way of going about it - I'm new to VBA and I am struggling to get loops to work and have the correct result. I have looked at while loops but not sure if this is the correct way to go?
Thanks very much for your time!
Edit: Added in the code so far - (I'm aware it is not good)!
Dim r As Range
Dim t As Range
Dim r2 As Range
Dim t2 As Range
Dim rData As Range
Set rData = Range("C4:C70")
Set r = Sheets("Sheet1").Range("D4")
Set r2 = Sheets("Sheet1").Range("C4")
Set t = Sheets("Sheet2").Range("D4")
Set t2 = Sheets("Sheet2").Range("C4")
For Each r2 In rData
If r.Value = "01/09/2018" Then
t = r
t2 = r.Offset(0, -1)
Set r = r.Offset(1, 0)
Set r2 = r2.Offset(1, 0)
Set t = t.Offset(1, 0)
Set t2 = t2.Offset(1, 0)
End If
If r.Value <> "" & r2.Value <> "" Then
Set r = r.Offset(1, 0)
Set r2 = r2.Offset(1, 0)
Set t = t.Offset(1, 0)
Set t2 = t2.Offset(1, 0)
End If
If r.Value = "01/10/2018" Then
t = r
t2 = r.Offset(0, -1)
End If
Next r2

For Eachloop that you had? It's okay if it doesn't work.