Hi,
I am writing my first "complicated" macro and have a question.
The macro will copy information from specific sheets and place them into a new workbook.
the problem is that thre are multiple workbooks with multiple worksheets. The worksheets are named consistently (plate 1, plate 2 etc), but not all workbooks have the same number of worksheets. Also, there are other worksheets in the workbooks which are not neeed, and threfore the worksheets of interest are not always in the same order (but at least the naming is consistent).
I am trying to write a macro that says
If worksheet named "plate1" is present
then select worksheet "plate1" copy data
else end the sub
followed by another if/then statement saying:
if worksheet named "plate2" is present
then select worksheet"plate2", copy data
else end of sub.
I am having trouble with the syntax checking whether a worksheet is present in the workbook.
I think I am on the right track. I'd appreciate any pointers.
thanks
here's the code if you'd like to see it:
Sub get_data2()
'
' get_data2 Macro
' Macro recorded 9/16/2002 by unstuck
'
' Keyboard Shortcut: Ctrl+m
'
ActiveWorkbook.Activate
Set myWorkbook = ActiveWorkbook
Worksheets("Cover Sheet").Activate
Range("B11").Select
Application.CutCopyMode = False
Selection.Copy
Windows("assemble.xls").Activate
ActiveCell.Offset(1, 0).Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
myWorkbook.Activate
Sheets("plate 1 analy").Select
Range("N5").Select
Application.CutCopyMode = False
Selection.Copy
Windows("assemble.xls").Activate
ActiveCell.Offset(0, 1).Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
myWorkbook.Activate
Range("A17:B25").Select
Application.CutCopyMode = False
Selection.Copy
Windows("assemble.xls").Activate
ActiveCell.Offset(0, 1).Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
ActiveCell.Offset(9, -2).Range("A1").Select
myWorkbook.Activate
If Sheets("plate 2 analy").exists = True Then
Sheets("plate 2 analy").Select
Range("N5").Select
Application.CutCopyMode = False
Selection.Copy
Windows("assemble.xls").Activate
ActiveCell.Offset(0, 1).Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
myWorkbook.Activate
Range("A17:B25").Select
Application.CutCopyMode = False
Selection.Copy
Windows("assemble.xls").Activate
ActiveCell.Offset(0, 1).Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
ActiveCell.Offset(9, -2).Range("A1").Select
Else: Exit Sub
End If
myWorkbook.Activate
If Sheets("plate 3 analy").Select = True Then
Sheets("plate 3 analy").Select
Range("N5").Select
Application.CutCopyMode = False
Selection.Copy
Windows("assemble.xls").Activate
ActiveCell.Offset(0, 1).Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Windows("Exp. 1.xls").Activate
Range("A17:B25").Select
Application.CutCopyMode = False
Selection.Copy
Windows("assemble.xls").Activate
ActiveCell.Offset(0, 1).Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
ActiveCell.Offset(9, -2).Range("A1").Select
Else: Exit Sub
End If
End Sub
I am writing my first "complicated" macro and have a question.
The macro will copy information from specific sheets and place them into a new workbook.
the problem is that thre are multiple workbooks with multiple worksheets. The worksheets are named consistently (plate 1, plate 2 etc), but not all workbooks have the same number of worksheets. Also, there are other worksheets in the workbooks which are not neeed, and threfore the worksheets of interest are not always in the same order (but at least the naming is consistent).
I am trying to write a macro that says
If worksheet named "plate1" is present
then select worksheet "plate1" copy data
else end the sub
followed by another if/then statement saying:
if worksheet named "plate2" is present
then select worksheet"plate2", copy data
else end of sub.
I am having trouble with the syntax checking whether a worksheet is present in the workbook.
I think I am on the right track. I'd appreciate any pointers.
thanks
here's the code if you'd like to see it:
Sub get_data2()
'
' get_data2 Macro
' Macro recorded 9/16/2002 by unstuck
'
' Keyboard Shortcut: Ctrl+m
'
ActiveWorkbook.Activate
Set myWorkbook = ActiveWorkbook
Worksheets("Cover Sheet").Activate
Range("B11").Select
Application.CutCopyMode = False
Selection.Copy
Windows("assemble.xls").Activate
ActiveCell.Offset(1, 0).Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
myWorkbook.Activate
Sheets("plate 1 analy").Select
Range("N5").Select
Application.CutCopyMode = False
Selection.Copy
Windows("assemble.xls").Activate
ActiveCell.Offset(0, 1).Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
myWorkbook.Activate
Range("A17:B25").Select
Application.CutCopyMode = False
Selection.Copy
Windows("assemble.xls").Activate
ActiveCell.Offset(0, 1).Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
ActiveCell.Offset(9, -2).Range("A1").Select
myWorkbook.Activate
If Sheets("plate 2 analy").exists = True Then
Sheets("plate 2 analy").Select
Range("N5").Select
Application.CutCopyMode = False
Selection.Copy
Windows("assemble.xls").Activate
ActiveCell.Offset(0, 1).Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
myWorkbook.Activate
Range("A17:B25").Select
Application.CutCopyMode = False
Selection.Copy
Windows("assemble.xls").Activate
ActiveCell.Offset(0, 1).Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
ActiveCell.Offset(9, -2).Range("A1").Select
Else: Exit Sub
End If
myWorkbook.Activate
If Sheets("plate 3 analy").Select = True Then
Sheets("plate 3 analy").Select
Range("N5").Select
Application.CutCopyMode = False
Selection.Copy
Windows("assemble.xls").Activate
ActiveCell.Offset(0, 1).Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Windows("Exp. 1.xls").Activate
Range("A17:B25").Select
Application.CutCopyMode = False
Selection.Copy
Windows("assemble.xls").Activate
ActiveCell.Offset(0, 1).Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
ActiveCell.Offset(9, -2).Range("A1").Select
Else: Exit Sub
End If
End Sub