In the code below, I need the macro to look through sheets in the workbook for sheet names that contain certain text. In this example main and ST (the full workbook name is much longer) when a sheet is found I need to copy a sheet from another workbook to insert next to it. I have managed to get excel to count the sheets and I believe I have got excel to work through the sheets, but I have come across the problem of now getting the macro to identify the sheet name against the variable that I used to work through the sheets (x). I am sure I am doing something very stupid but cannot work how to make it then look at the name of the sheet. My code is as follows.
Any guidance on allowing me to move forward would be very welcome.
Kind regards
Sub JNinternalOrder()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
'This coding ensures that the file has been inserted and positioned in the correct place
'The relevant Jane Stilton file needs to be run and then copied and pasted into the Gabor file
'in order for this macro to run.
Dim response As String
response = MsgBox("Have you copied the address list to page 1 of the JN split macro and named the sheet with the file name eg: JN00012?", vbQuestion + vbYesNo)
If response = vbNo Then
MsgBox ("Please copy the file over and then restart the macro")
Exit Sub
End If
Dim x, totalsheets
x = 1
totalsheets = ActiveWorkbook.Sheets.Count
Do Until x = totalsheets
If x.worksheetName Like "*Main*ST*" Then (runtime error424 occuring here so my x does not mean anything to the macro)
Call copysheet
End If
Loop
End Sub
Sub copysheet() (not yet tested as I could not get the top bit working)
'Dim oBook As Workbook
Dim wb As Workbook, totalsheets, sh1 As Workbook
totalsheets = ActiveWorkbook.Sheets.Count
Set sh1 = ThisWorkbook
Set wb = Workbooks("lookupfiles.xls").Worksheets("jewio").Activate
Worksheets("jewio").Copy Before:=sh1(x)
End Sub
Any guidance on allowing me to move forward would be very welcome.
Kind regards
Sub JNinternalOrder()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
'This coding ensures that the file has been inserted and positioned in the correct place
'The relevant Jane Stilton file needs to be run and then copied and pasted into the Gabor file
'in order for this macro to run.
Dim response As String
response = MsgBox("Have you copied the address list to page 1 of the JN split macro and named the sheet with the file name eg: JN00012?", vbQuestion + vbYesNo)
If response = vbNo Then
MsgBox ("Please copy the file over and then restart the macro")
Exit Sub
End If
Dim x, totalsheets
x = 1
totalsheets = ActiveWorkbook.Sheets.Count
Do Until x = totalsheets
If x.worksheetName Like "*Main*ST*" Then (runtime error424 occuring here so my x does not mean anything to the macro)
Call copysheet
End If
Loop
End Sub
Sub copysheet() (not yet tested as I could not get the top bit working)
'Dim oBook As Workbook
Dim wb As Workbook, totalsheets, sh1 As Workbook
totalsheets = ActiveWorkbook.Sheets.Count
Set sh1 = ThisWorkbook
Set wb = Workbooks("lookupfiles.xls").Worksheets("jewio").Activate
Worksheets("jewio").Copy Before:=sh1(x)
End Sub