Zab Trader
New Member
- Joined
- Feb 19, 2019
- Messages
- 5
Just added the top part of code to select file instead of having it hard coded.
How do I go about adjusting the 2nd part so I can use it instead of the hard coded file.
ChDrive "c:"
NewFN = Application.GetOpenFilename(FileFilter:="Excel Files (*.xlsx), *.xlsx", Title:="Please select a file")
If NewFN = False Then
MsgBox "Stopping because you did not select a file"
Exit Sub
Else
Workbooks.Open Filename:=NewFN
End If
Dim sPath As String
Dim sFileName As String '
Dim wsSummary As Worksheet
Dim wsData As Worksheet 'sheet with data to copy
Dim wb As Workbook 'workbooks to loop thorugh
Set wsSummary = ThisWorkbook.Worksheets("Sheet1")
sPath = "C:\Workfiles"
sFileName = Dir(sPath & "Valdatacopy.xlsx")
Set wb = Workbooks.Open(Filename:=sPath & sFileName, ReadOnly:=True)
Set wsData = wb.Sheets("Sheet1")
LastRow1 = wb.Worksheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row
Set wb = Workbooks.Open(Filename:=sPath & sFileName, ReadOnly:=True)
Set wsData = wb.Sheets("Sheet1")
wsSummary.Range("A3:A3" & LastRow1).Value = wsData.Range("F3:F3" & LastRow1).Value
wsSummary.Range("B3:B3" & LastRow1).Value = wsData.Range("D3:D3" & LastRow1).Value
wb.Close
<strike></strike>
<strike></strike>Appreciate the help! Thank You
Zab
How do I go about adjusting the 2nd part so I can use it instead of the hard coded file.
ChDrive "c:"
NewFN = Application.GetOpenFilename(FileFilter:="Excel Files (*.xlsx), *.xlsx", Title:="Please select a file")
If NewFN = False Then
MsgBox "Stopping because you did not select a file"
Exit Sub
Else
Workbooks.Open Filename:=NewFN
End If
Dim sPath As String
Dim sFileName As String '
Dim wsSummary As Worksheet
Dim wsData As Worksheet 'sheet with data to copy
Dim wb As Workbook 'workbooks to loop thorugh
Set wsSummary = ThisWorkbook.Worksheets("Sheet1")
sPath = "C:\Workfiles"
sFileName = Dir(sPath & "Valdatacopy.xlsx")
Set wb = Workbooks.Open(Filename:=sPath & sFileName, ReadOnly:=True)
Set wsData = wb.Sheets("Sheet1")
LastRow1 = wb.Worksheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row
Set wb = Workbooks.Open(Filename:=sPath & sFileName, ReadOnly:=True)
Set wsData = wb.Sheets("Sheet1")
wsSummary.Range("A3:A3" & LastRow1).Value = wsData.Range("F3:F3" & LastRow1).Value
wsSummary.Range("B3:B3" & LastRow1).Value = wsData.Range("D3:D3" & LastRow1).Value
wb.Close
<strike></strike>
<strike></strike>Appreciate the help! Thank You
Zab