Hi I wrote a code to open a file name which contains buoy1xxxxx
ub OpenTextfile()
Windows("hello world.xlsm").Activate
Sheets("User Input").Select
Dim FilePath As String, fileName As String
FilePath = Cells(2, 2)
fileNameBuoy1 = Dir(FilePath & "Buoy1*.xl??")
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Do While fileNameBuoy1 <> ""
Workbooks.Open (FilePath & fileNameBuoy1)
Sheets(1).Select
Columns("A:A").Select
Selection.TextToColumns _
Destination:=Range("A1"), _
DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=False, _
Tab:=False, _
Semicolon:=True, _
Comma:=False, _
Space:=False, _
Other:=True, _
OtherChar:="-"
Cells.Select
Selection.Copy
Windows("hello world.xlsm").Activate
Sheets("Hello World").Select
Range("A1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("A4", Selection.End(xlDown)).Select
Application.CutCopyMode = False
Selection.NumberFormat = "0"
Workbooks(fileNameBuoy1).Close False
Call lookupHs24Hr
Call lookupHs48Hr
Call lookupHs72Hr
Call lookupHs5Days
Call lookupTp24Hr
Call lookupTp48Hr
Call lookupTp72Hr
Call lookupTp5Days
Call lookupwd24Hr
Call lookupwd48Hr
Call lookupwd72Hr
Call lookupwd5Days
Sheets("Hello World").Cells.ClearContents
fileNameBuoy1 = Dir()
Loop
When i want to open another file name which contain Buoy2, i added additional code
Windows("hello world.xlsm").Activate
Sheets("User Input").Select
Dim FilePath As String, fileName As String
FilePath = Cells(2, 2)
fileNameBuoy1 = Dir(FilePath & "Buoy1*.xl??")
fileNameBuoy2 = Dir(FilePath & "Buoy2*.xl??"
Application.ScreenUpdating = False
Application.DisplayAlerts = False
as well as a Do While loop with all the name changed from fileNameBuoy1 to fileNameBuoy 2
However it gives error at
it works perfectly for only filenameBuoy1. However it gives error once i added the Buoy 2 code. May I know why?Thanks!
Bookmarks