Excel to complete the missing date in a range

ExcelNewbie2020

Active Member
Joined
Dec 3, 2020
Messages
282
Office Version
  1. 365
Platform
  1. Windows
Gurus,

Is there a way that excel can be able to complete a missing date in a date range.. see below..

Book1
ABC
2SOURCE DATA
3NAME101-08-2208-24-2022 12:00
4NAME102-08-2208-22-2022 10:00
5NAME108-08-2208-22-2022 10:00
6NAME201-08-2208-24-2022 12:00
7NAME205-08-2208-22-2022 10:00
8NAME206-08-2208-24-2022 12:00
9NAME207-08-2208-24-2022 12:00
10NAME210-08-2208-22-2022 10:00
11
12
13EXPECTED RESULT
14
15NAME101-08-2208-24-2022 12:00
16NAME102-08-2208-22-2022 10:00
17NAME103-08-22
18NAME104-08-22
19NAME105-08-22
20NAME106-08-22
21NAME107-08-22
22NAME108-08-2208-22-2022 10:00
23NAME201-08-2208-24-2022 12:00
24NAME202-08-22
25NAME203-08-22
26NAME204-08-22
27NAME205-08-2208-22-2022 10:00
28NAME206-08-2208-24-2022 12:00
29NAME207-08-2208-24-2022 12:00
30NAME208-08-22
31NAME209-08-22
32NAME210-08-2208-22-2022 10:00
Sheet1
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Try this code. The result starts from cell F2. Change it as required.
VBA Code:
Sub MissingDates()
Dim A
Dim T As Long, Ta As Long, X As Long, Y As Long

A = Range("A2").CurrentRegion.Offset(1, 0)
ReDim C(1 To 10 * UBound(A, 1), 1 To 3)
For T = 1 To UBound(A, 1) - 1
X = X + 1
C(X, 1) = A(T, 1): C(X, 2) = A(T, 2): C(X, 3) = A(T, 3)
If A(T, 1) = A(T + 1, 1) And A(T + 1, 2) > A(T, 2) + 1 Then
    For Ta = A(T, 2) + 1 To A(T + 1, 2) - 1
    X = X + 1: Y = Y + 1
    C(X, 1) = A(T, 1): C(X, 2) = A(T, 2) + Y
    Next Ta
End If
Y = 0
Next T
Range("F2").CurrentRegion.Clear
Range("F2").Resize(X, 3) = C

End Sub
 
Upvote 0
Solution
Try this code. The result starts from cell F2. Change it as required.
VBA Code:
Sub MissingDates()
Dim A
Dim T As Long, Ta As Long, X As Long, Y As Long

A = Range("A2").CurrentRegion.Offset(1, 0)
ReDim C(1 To 10 * UBound(A, 1), 1 To 3)
For T = 1 To UBound(A, 1) - 1
X = X + 1
C(X, 1) = A(T, 1): C(X, 2) = A(T, 2): C(X, 3) = A(T, 3)
If A(T, 1) = A(T + 1, 1) And A(T + 1, 2) > A(T, 2) + 1 Then
    For Ta = A(T, 2) + 1 To A(T + 1, 2) - 1
    X = X + 1: Y = Y + 1
    C(X, 1) = A(T, 1): C(X, 2) = A(T, 2) + Y
    Next Ta
End If
Y = 0
Next T
Range("F2").CurrentRegion.Clear
Range("F2").Resize(X, 3) = C

End Sub
and it worx like a charm.. thank you very much
 
Upvote 0

Forum statistics

Threads
1,213,543
Messages
6,114,236
Members
448,555
Latest member
RobertJones1986

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top