Hello all,
I have a macro that is opening up several workbooks using hyperlinks. Each workbook has a different name(CT.xls, BB.xls etc). The macro copies a static range of data from each of these sheets and then and pastes it into a workbook called "Extractor". I only have 2 workbooks open at any time, the "Extractor" and the book I'm copying from.
The problem I have is that when I switch between workbooks, I am referring to the workbooks by their unique name which makes the macro very very long.
Is there a way to change this so I can either refer to them with a generic name in VBA or is there a way you can set up a macro to say "Select workbook that isn't active"?
Thanks for any help you guys can give me. I've attached my...rather large macro below. I'm sure it's really very messy.
Cat80
Sub SLEA()
'
' SLEA1 Macro
Application.DisplayAlerts = False
Sheets("Sheet1").Select
Range("A1").Select
Selection.Hyperlinks(1).Follow NewWindow:=False, AddHistory:=True
Sheets("FP and LL MD and BoM Control").Select
Range("D11").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Windows("SLEA Extractor.xlsm").Activate
Sheets("BOM").Select
Range("FreecellBOM").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Windows("CT.xlsx").Activate
Sheets("Control Document").Visible = True
Range("A6").Select
Range(Selection, Selection.End(xlToRight)).Select
ActiveWindow.SmallScroll Down:=-3
Application.CutCopyMode = False
Sheets("Control Document").Select
Range("A6:N499").Select
Range("A500").Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.AutoFill Destination:=Range("A500:M1000"), Type:=xlFillDefault
Range("A500:M1000").Select
Range("A6").Select
ActiveSheet.Range("$A$6:$N$1000").AutoFilter Field:=5, Criteria1:="<>"
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Windows("SLEA Extractor.xlsm").Activate
Sheets("MD").Select
Range("Freecell").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Windows("CT.xlsx").Activate
Sheets("Control Document").Select
ActiveWindow.SelectedSheets.Visible = False
ActiveWindow.Close
I have a macro that is opening up several workbooks using hyperlinks. Each workbook has a different name(CT.xls, BB.xls etc). The macro copies a static range of data from each of these sheets and then and pastes it into a workbook called "Extractor". I only have 2 workbooks open at any time, the "Extractor" and the book I'm copying from.
The problem I have is that when I switch between workbooks, I am referring to the workbooks by their unique name which makes the macro very very long.
Is there a way to change this so I can either refer to them with a generic name in VBA or is there a way you can set up a macro to say "Select workbook that isn't active"?
Thanks for any help you guys can give me. I've attached my...rather large macro below. I'm sure it's really very messy.
Cat80
Sub SLEA()
'
' SLEA1 Macro
Application.DisplayAlerts = False
Sheets("Sheet1").Select
Range("A1").Select
Selection.Hyperlinks(1).Follow NewWindow:=False, AddHistory:=True
Sheets("FP and LL MD and BoM Control").Select
Range("D11").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Windows("SLEA Extractor.xlsm").Activate
Sheets("BOM").Select
Range("FreecellBOM").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Windows("CT.xlsx").Activate
Sheets("Control Document").Visible = True
Range("A6").Select
Range(Selection, Selection.End(xlToRight)).Select
ActiveWindow.SmallScroll Down:=-3
Application.CutCopyMode = False
Sheets("Control Document").Select
Range("A6:N499").Select
Range("A500").Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.AutoFill Destination:=Range("A500:M1000"), Type:=xlFillDefault
Range("A500:M1000").Select
Range("A6").Select
ActiveSheet.Range("$A$6:$N$1000").AutoFilter Field:=5, Criteria1:="<>"
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Windows("SLEA Extractor.xlsm").Activate
Sheets("MD").Select
Range("Freecell").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Windows("CT.xlsx").Activate
Sheets("Control Document").Select
ActiveWindow.SelectedSheets.Visible = False
ActiveWindow.Close