PDA

View Full Version : [SOLVED] Modify code to look for certain sheetnames



elmnas
07-28-2015, 01:56 AM
Hello Excel people,
I have wrote following code,
it's pretty simple the code looking for the sheetname "test_me*"
IF found copy data from certain columns in sheet "test_me*" into sheetname called "My_Statistik"
Now I need to change the code because if sheet "test_me*" doesn't exist
look for following sheetnames:
test 3P
test Bus
test Business Service
test Group Sweden
test IT

and do exactly the same thing copy from same columns and paste in the sheet my_statistik

See code below:


Sub GetData()
For Each sht In ThisWorkbook.Worksheets
mysheetname = sht.Name
If sht.Name Like "test_me*" Then
Sheets(mysheetname).Select
Columns("A:A").Select
Selection.Copy
Sheets("My_Statistik").Select
Columns("A:A").Select
ActiveSheet.Paste
Sheets(mysheetname).Select
Columns("C:C").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("My_Statistik").Select
Columns("F:F").Select
ActiveSheet.Paste
Sheets(mysheetname).Select
Columns("D:E").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("My_Statistik").Select
Columns("K:K").Select
Columns("J:J").Select
ActiveSheet.Paste
Sheets(mysheetname).Select
Columns("G:I").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("My_Statistik").Select
Columns("L:L").Select
ActiveSheet.Paste
Sheets(mysheetname).Select
Columns("L:L").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("My_Statistik").Select
Columns("W:W").Select
ActiveSheet.Paste
Sheets(mysheetname).Select
Columns("N:N").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("My_Statistik").Select
Columns("AB:AB").Select
ActiveSheet.Paste
End If
Next sht
End Sub

Could someone help me?
Thank you in advance