rename & hide worksheet problem
Hi
Not working isn't a very helpful description of the problem but looking at
the code you are testing the leftmost 20 characters and then when you find
that sheet you are making an assumption there are only 20 characters in the
sheet name. Try this
Sub Checksheets()
Dim Flag As Integer
x = WorksheetFunction.Text(Now(), "dd-mm-yy at hhmm")
Flag = 0
For Each sh In Worksheets
If Left(sh.Name, 20) = "Booking Form Revised" Then
sh.Name = "Old BKF chgd " & x
Flag = Flag + 1
sh.Visible = xlSheetHidden
End If
Next
If Flag = 0 Then
MsgBox Flag
'Call RevisedMBA
End If
End Sub
Mike
"BeSmart" wrote:
Hi All
I can't work out why my code is not working here?
I need to find a worksheet, rename and hide it before I can run the next
code...
The code needs to:
- Find any worksheet names starting from the left with the following 20
characters:
"booking form revised"
(any hidden sheets can be ignored)
- If it doesn't find any worksheets with this name then skip the rest of
the macro and call "RevisedMBA"
- If it does find a worksheet - Rename that worksheet to: "Old BKF chgd " & x
(x = WorksheetFunction.Text(Now(), "dd-mm-yy at hhmm")
I know that I'm limited to 31 characters in a worksheet name - I've kept
under that - just with 29.
- Hide the renamed "Old BKF chgd " & x worksheet
- Now call RevisedMBA.
Current Code:
_________________________________
Sub Checksheets()
Dim Flag As Integer
x = WorksheetFunction.Text(Now(), "dd-mm-yy at hhmm")
Flag = 0
For Each sh In Worksheets
If Left(sh.Name, 20) = "Booking Form Revised" Then
Sheets("Booking Form Revised").Name = "Old BKF chgd " & x
Flag = Flag + 1
sh.Visible = xlSheetHidden
End If
Next
If Flag = 0 Then
Call RevisedMBA
End If
End Sub
_____________________
--
Thank for your help
BeSmart
|