Situation... I have inheirited a fairly involved excel macro and am running into a problem... THis macro imports a number of files as seperate worksheets, then reorganizes the data in the worksheets and copies it to a central sheet and does some calucations... THe problem is that the macro has a section for editing each workstheet... THere is a sample below... Basically, the script runs "Batch1_GETS, Batch2_GETS, and so on till Batch8_GETS, This edits the data on th worksheet and then copies data to another worksheet after the fact (ParaSoft_Data) for additional calculations... IT woks fine, but the problem is that now the number of batches has now started varying. Now alot of the time we only get Batch 1-6, but we still on occation get 8, so I don't want to remove that section of the code in the macro... The problem is that since there is no Batch7/8 worksheet that when it gets to the Batch7_GETS section in the macro, it causes problems.
Normally, i would a IF NOT EXIST/ GOTO statement... Basically, I would note in the code - that if something didn't exist (ie Batch7/8_GETS worksheets) it would just skip that section and go on... I know that excel has IF/ElSE statements - but I can't get it work... So I figured I would ask... I would think it shouldn't be too difficult, so if anyone if familiar, I would appreciate some help....
Ultimately, I would prefer to loop the BatchX_GETS statements, so there wasn't a seperate piece for each workbook, but one thing at a time...
Thansks in advance..
' Batch1_GETS
Sheets("Batch1_GETS").Select
Columns("C:L").Select
Selection.Delete Shift:=xlToLeft
Columns("A:B").Select
ActiveWorkbook.Worksheets("Batch1_GETS").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Batch1_GETS").Sort.SortFields.Add Key:=Range( _
"B2:B135"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("Batch1_GETS").Sort
.SetRange Range("A1:B135")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Rows("2:90").Select
Selection.Delete Shift:=xlUp
Range("A2:B46").Select
Selection.Copy
ActiveWindow.ScrollWorkbookTabs Sheets:=-1
ActiveWindow.ScrollWorkbookTabs Sheets:=-1
ActiveWindow.ScrollWorkbookTabs Sheets:=-1
Sheets("ParaSoft Data").Select
Range("A3").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
' Batch2_GETS
Sheets("Batch2_GETS").Select
Columns("C:L").Select
Selection.Delete Shift:=xlToLeft
Columns("A:B").Select
ActiveWorkbook.Worksheets("Batch2_GETS").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Batch2_GETS").Sort.SortFields.Add Key:=Range( _
"B2:B135"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("Batch2_GETS").Sort
.SetRange Range("A1:B135")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Rows("2:90").Select
Selection.Delete Shift:=xlUp
Range("A2:B46").Select
Selection.Copy
ActiveWindow.ScrollWorkbookTabs Sheets:=-1
ActiveWindow.ScrollWorkbookTabs Sheets:=-1
ActiveWindow.ScrollWorkbookTabs Sheets:=-1
Sheets("ParaSoft Data").Select
Range("F3").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Moderator's note: Please take the time to review our rules. There aren't many, and they are all important. Rule #3 requires code tags. I have added them for you this time because you are a new member. --6StringJazzer
Bookmarks