Hello,
I have an excel 2007 spreadsheet that imports data from a PeopleSoft Query output (excel). The code works perfectly when the headers are in the same place (row 3) but depending on how you run the query (straight to excel or scheduler) you will get extra rows for the prompts (5).
What I need to do is build in code to find the first header which is "EE ID" and then import the row to 500 after that. Any ideas on how I can accomplish this??
Here is my code:
I have an excel 2007 spreadsheet that imports data from a PeopleSoft Query output (excel). The code works perfectly when the headers are in the same place (row 3) but depending on how you run the query (straight to excel or scheduler) you will get extra rows for the prompts (5).
What I need to do is build in code to find the first header which is "EE ID" and then import the row to 500 after that. Any ideas on how I can accomplish this??
Here is my code:
Code:
Private Sub cmdImport_Click()
Dim ImportFile As String
Dim ImportTitle As String
Dim TabName As String
Dim ControlFile As String
'Open common dialog and get filename
ImportFile = Application.GetOpenFilename( _
"Excel Files, *.xls,All Files, *.*")
ImportTitle = _
Mid(ImportFile, InStrRev(ImportFile, "\") + 1)
'Check cancel wasn't clicked
If ImportFile = "False" Then
Exit Sub
End If
'Import file
TabName = "DataEntry"
ControlFile = ActiveWorkbook.Name
Workbooks.Open FileName:=ImportFile
ActiveSheet.Name = TabName
Range("A3:W500").Select
Selection.Copy
Windows(ControlFile).Activate
Sheets("DataEntry").Select
ActiveSheet.Range("A65536").End(xlUp).Offset(1, 0).Select 'starts at row 65536, goes up to the last row of data and then offsets one row
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Windows(ImportTitle).Activate
Application.CutCopyMode = False
ActiveWorkbook.Close SaveChanges:=False
Windows(ControlFile).Activate
Sheets("DataEntry").Select
'Range("A5:AA60000").Select
'Selection.Sort Key1:=Range("F5"), Order1:=xlAscending, Header:=xlGuess, OrderCustom:=1, MatchCase:= _
'False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal
Application.CutCopyMode = True
MsgBox "Data has been successfully imported!"
UserForm2.Hide
End Sub