Hi,
I have two issues that i am trying to resolve. I have a code that basically formats and combine multiple selected excel files. Problem 1. the macro doesn't always work (maybe i need to restart comp or restart excel? refresh issue?) 2. I need help with naming the worksheet based on a cell value/text.
currently i have a code to pull/extract numbers within parenthasis. however sometimes the sheet may not have numbers. so i need it to say if there's (12345) name sheet 12345, if there's no (12345 or similar), name sheet (basketball) baskeball. the cell range will always start with account:
Code
ChDrive "G"
ChDir "G:\OPERATNS\a"
Z = Application.GetOpenFilename(Title:="Select a file or files", _
MultiSelect:=True)
If TypeName(Z) = "Boolean" Then Exit Sub
Application.ScreenUpdating = False
Application.DisplayAlerts = False
On Error Resume Next
For x = 1 To UBound(Z)
Set wb = Workbooks.Open(Z(x))
For Each ws In ActiveWorkbook.Worksheets
'For Each ws In wb.Worksheets
ws.Select
ActiveSheet.Outline.ShowLevels RowLevels:=2
Range("G:M,O:Q,S:T,V:AV").EntireColumn.Hidden = True
Cells.Find(What:="Identifier", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).Activate
ActiveCell.Offset(4, -1).Select
ActiveWindow.FreezePanes = True
Cells.Find(What:="Equivalents", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).Activate
Selection.EntireRow.ShowDetail = False
txt = Range("a5").Value
With CreateObject("VBScript.RegExp")
.Pattern = "\(([^\)-]+)[^\)]*\)$"
If .test(txt) Then ws.Name = .Execute(txt)(0).submatches(0)
End With
wb.Sheets.Copy Before:=ThisWorkbook.Sheets(1)
wb.Close False
Next ws
For Each ws In ActiveWorkbook.Worksheets
ws.Select
If Application.CountA(ws.Cells) = 0 Then ws.Delete
Next ws
Next x
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
Display More