Excel to complete the missing date in a range

ExcelNewbie2020

Board Regular
Joined
Dec 3, 2020
Messages
133
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

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.

kvsrinivasamurthy

Well-known Member
Joined
Nov 6, 2013
Messages
1,028
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

ExcelNewbie2020

Board Regular
Joined
Dec 3, 2020
Messages
133
Office Version
  1. 365
Platform
  1. Windows
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,186,769
Messages
5,959,649
Members
438,440
Latest member
Hi577

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
Top