steimel386
New Member
- Joined
- Jan 8, 2009
- Messages
- 33
Hey everyone. I have a problem that seems simple but I really can't find an answer:
I'm trying to simplify my macro which opens all of the excel files in the directory and pulls data from a specific worksheet. The problem is that now there is two worksheets; Work(OPT#1) and Work(OPT #1) --- notice the space. The only way around that as of now is to simply run the macro twice, pulling files from tab name A and then again (inefficiently) on tab name B.
What I would like to do is rename those tabs to remove the space or use the TRIM function if possible. I've included what I have below, thanks a lot and any help is really appreciated.
I'm trying to simplify my macro which opens all of the excel files in the directory and pulls data from a specific worksheet. The problem is that now there is two worksheets; Work(OPT#1) and Work(OPT #1) --- notice the space. The only way around that as of now is to simply run the macro twice, pulling files from tab name A and then again (inefficiently) on tab name B.
What I would like to do is rename those tabs to remove the space or use the TRIM function if possible. I've included what I have below, thanks a lot and any help is really appreciated.
Code:
Sub SheetConditioner() 'this is based off of the same macro that extracts
'the data from the workbooks -- it seemed like if this would open the files
'then it could also probabaly rename them
n = 3
On Error Resume Next
With Application.FileSearch
.LookIn = ThisWorkbook.Path
.FileType = msoFileTypeExcelWorkbooks
.SearchSubFolders = True
.Execute
For i = 1 To (.FoundFiles.Count - 1)
'If Workbooks(.FoundFiles(i)).Name = ThisWorkbook.Name Then GoTo NotMe
Workbooks.Open .FoundFiles(i)
n = n + 1
With Sheets("work(opt #1)").Activate
MatchCase = False
Sheets("Work(OPT #1)").Name = "Work(OPT#1)"
'ThisWorkbook.Sheets("Jan09_NoSpace").Cells(n, 1).Value = .Range("F1").Value
'ThisWorkbook.Sheets("Jan09_NoSpace").Cells(n, 163).Value = ("Jan '09")
End With
ActiveWorkbook.Close False
NotMe:
Next
End With
End Sub