I hope someone can help me.
I have a vba script that combines equipment from multiple excel files. The problem I have is trying to compare 2 files for similar worksheet names. If names are similar then I need to add a worksheet in the new workbook after the matching sheeet.
I have attached what I have so far. The first part of the for each sht works great. I tried making it sht2 but that didn't help. What am I missing?
For Each sht In Application.Worksheets
If sht.Name <> "templates" Then
If Range("l23,l115,l207") <> True Then
sht.Range("uio_equip").Copy
newbook.Activate
Set sht = Worksheets.Add(After:=Worksheets(Worksheets.Count))
Range("b2").Select
Selection.PasteSpecial Paste:=xlPasteValues
sht.Name = "uio_" & Range("f2")
newbook.Save
ElseIf Range("l23,l115,l207") = True Then
uioname = Range("f2")
sht.Range("uio_equip").Copy
newbook.Activate
IF SHT.NAME LIKE UIONAME THEN 'this is where I trying to get a 2nd loop of worksheets within the newbook.
wksh.Activate
Set sht = Worksheets.Add(After:=Worksheets(Worksheets.Count))
Range("b2").Select
Selection.PasteSpecial Paste:=xlPasteValues
sht.Name = "uio_" & Range("f2")
newbook.Save
End If
End If
'clears clipboard
Application.CutCopyMode = False
End If
Next sht
Any help would be greatly appreciated.
I have a vba script that combines equipment from multiple excel files. The problem I have is trying to compare 2 files for similar worksheet names. If names are similar then I need to add a worksheet in the new workbook after the matching sheeet.
I have attached what I have so far. The first part of the for each sht works great. I tried making it sht2 but that didn't help. What am I missing?
For Each sht In Application.Worksheets
If sht.Name <> "templates" Then
If Range("l23,l115,l207") <> True Then
sht.Range("uio_equip").Copy
newbook.Activate
Set sht = Worksheets.Add(After:=Worksheets(Worksheets.Count))
Range("b2").Select
Selection.PasteSpecial Paste:=xlPasteValues
sht.Name = "uio_" & Range("f2")
newbook.Save
ElseIf Range("l23,l115,l207") = True Then
uioname = Range("f2")
sht.Range("uio_equip").Copy
newbook.Activate
IF SHT.NAME LIKE UIONAME THEN 'this is where I trying to get a 2nd loop of worksheets within the newbook.
wksh.Activate
Set sht = Worksheets.Add(After:=Worksheets(Worksheets.Count))
Range("b2").Select
Selection.PasteSpecial Paste:=xlPasteValues
sht.Name = "uio_" & Range("f2")
newbook.Save
End If
End If
'clears clipboard
Application.CutCopyMode = False
End If
Next sht
Any help would be greatly appreciated.