Need to Import Data Into Excel Only If It Matches Header Row

drmingle

Board Regular
Joined
Oct 5, 2009
Messages
229
Objective: From within an Excel sheet I want a user to select another file to import. However, I only want it to import the source data if the header matches exactly what is located in the dashboard file.

Dashboard File: Field1,...,Field9 (row1) - worksheet name: Data
Data Source File: Field1,...,Field9 (row1) - worksheet name: Sheet 1

The above must exactly match or I need to throw an error the exits the sub.

Here are the code snippets which work independently, but I need help either swapping them out or working them together:


Code:
Sub GetFile()Dim fNameAndPath As Variant, wb As Workbook
fNameAndPath = Application.GetOpenFilename(FileFilter:="Excel Files (*.XLS), *.XLS", Title:="Select File To Be Opened")
If fNameAndPath = False Then Exit Sub
Set wb = Workbooks.Open(fNameAndPath)
'
Call AddData
'
wb.Close savechanges:=True 'or false
End Sub

Not sure about this one...
Code:
Sub AddData()    Dim i As Integer
    Dim lw As Long
    Dim j As Integer
     
    lw = Range("E" & Rows.Count).End(xlUp).Row
     
    For i = lw To 2 Step -1
        If Range("E" & i).Value = "Yes" Then
            For j = 7 To 13
                Cells(i, j) = Date
            Next j
        End If
    Next i
     
End Sub

Any help would be appreciated...
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.

Forum statistics

Threads
1,215,429
Messages
6,124,841
Members
449,193
Latest member
MikeVol

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