StevenAncel
New Member
- Joined
- Dec 9, 2015
- Messages
- 38
I need my macro to be modified.
Right now it:
I need it to detect if the tab name already exist
If the tab name exist:
If it doesn't exist:
Right now it:
- Copies range from 'Order Type vLookup' tab
- Opens files from folder i choose (when prompted)
- Adds new tab to each opened workbook
- Paste the information
- Rename new tab: Order Type vLookup'
- Save and Close Workbook
- Loop for each file in folder
I need it to detect if the tab name already exist
If the tab name exist:
- Close Workbook
- Continue to the next file in the folder
- Loop through all files in folder
If it doesn't exist:
- Paste the information
- Rename new tab: Order Type vLookup'
- Save and Close Workbook
- Loop through all files in folder
Code:
Sub Copy_OrderTypevLookup()Dim Fpath As String
Dim Fname As String
Dim fd As FileDialog
Set fd = Application.FileDialog(msoFileDialogFolderPicker)
fd.InitialFileName = "\\ac.local\AC-DFS\UserData\steven.lawson\Desktop\Justins Macro\"
fd.InitialView = msoFileDialogViewList
fd.AllowMultiSelect = True
With fd
If .Show = False Then Exit Sub
Fpath = .SelectedItems(1)
End With
Fname = Dir(Fpath & "\*.xlsx")
Sheets("Order Type vLookup").Select
Range("A1:C1").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Sheets("Order Type vLookup").Select
Range("A1").Select
Do While Fname <> ""
Workbooks.Open Fpath & "\" & Fname
With Sheets(1)
Sheets("Sheet1").Activate
Sheets.Add After:=ActiveSheet
Selection.PasteSpecial Paste:=xlPasteColumnWidths, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
ActiveSheet.Paste
ActiveSheet.Name = "Order Type vLookup"
Range("A1").Select
End With
Range("A1").Select
ActiveWorkbook.Close True
Fname = Dir
Loop
End Sub