Fill in missing dates and data VBA

emilemil222

New Member
Joined
May 8, 2020
Messages
1
Office Version
  1. 365
Platform
  1. Windows
Hi All,

I have a data of 3 years daily exchange rate history. However, some dates (weekends, holidays) with corresponding rates are missing. I would like to fill in missing dates and copy the previous day's rates (for which data is missing) to missing date. So, in the example, the dates 15/01/2017 & 16/01/2017 are missing. So it is required to insert two rows for these dates and copy 13/01/2017's data there. Is there a possibilty to do this on VBA as I need to do this for three year's data?

Many thanks,

Снимок4.PNG
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Suggest you add your file sample using XL2BB so that we don't have to re-type your data. Help us to help you.
 
Upvote 0
Hi,
Welcome to MrExcel.
Check if that's what you're looking for :)

VBA Code:
Sub FillInMissingData()
    Dim lRow&
    Dim i&
    Const mainCol$ = "A"
    
    If Range(mainCol & 1).CurrentRegion.Rows.Count = 1 Then
        MsgBox "No data found"
        Exit Sub
    End If
    
    i = 2
    Do While Cells(i, mainCol) <> ""
        If Cells(i, mainCol).Offset(1, 0) - Cells(i, mainCol) > 1 Then
            Rows(i).Offset(1).Insert
            Cells(i, mainCol).EntireRow.Copy Cells(i, mainCol).Offset(1, 0)
            Cells(i, mainCol).Offset(1, 0) = Cells(i, mainCol) + 1
        End If
        i = i + 1
    Loop
    
    MsgBox "Done"
    
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,816
Messages
6,181,139
Members
453,021
Latest member
Justyna P

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