I've been working on a code for some time now. I think I am over complicating the coding for this macro. Essentially what I want it to be able to do is copy a date from a variable range cell that contains a selectable date and copy it as the worksheet name. I want the macro to error out and supply a message if a worksheet with that name already exists. I am going to assign the macro to a button.
In fool proofing this workbook... I feel as though I have become the fool.
This is why I have asked for a 936pg VBA programming book for Christmas...
Here is the coding that I have so far:
Sub Submit_For_Archiving()
' Submit_For_Archiving Macro
' Macro recorded 12/8/2008 by MBRADB3
Dim ws As Worksheet, sExist As Boolean
For Each ws In Worksheets
If UCase(ws.Range("D4")) = UCase(ws.Name) Then
sExist = True
Exit For
End If
Next
If sExist = True Then
MsgBox "This date already exists. Please make sure the date selected reflects the correct weeks production"
Else
ActiveSheet.Unprotect
Sheets("Production Board").Select
Sheets("Production Board").copy Before:=Sheets(1)
Sheets("Production Board (2)").Select
On Error Resume Next
For Each ws In Worksheets
If (ws.Range("D4")) = "" Then
ws.Name = "Sheet" & ws.Index
Else
ws.Name = Format(ws.Range("D4"), "mm-dd-yyyy")
End If
Next
ActiveSheet.Shapes("Text Box 1").Select
Selection.delete
ActiveSheet.Shapes("Text Box 2").Select
Selection.delete
ActiveSheet.Shapes("Text Box 3").Select
Selection.delete
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
Sheets("Production Board").Select
Range("C6:I8,C10:I12,C14:I16,C21:I23").Select
Range("I21").Activate
Selection.ClearContents
Range("C6").Select
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
Sheets("Production Board").Select
End If
End Sub
In fool proofing this workbook... I feel as though I have become the fool.
This is why I have asked for a 936pg VBA programming book for Christmas...
Here is the coding that I have so far:
Sub Submit_For_Archiving()
' Submit_For_Archiving Macro
' Macro recorded 12/8/2008 by MBRADB3
Dim ws As Worksheet, sExist As Boolean
For Each ws In Worksheets
If UCase(ws.Range("D4")) = UCase(ws.Name) Then
sExist = True
Exit For
End If
Next
If sExist = True Then
MsgBox "This date already exists. Please make sure the date selected reflects the correct weeks production"
Else
ActiveSheet.Unprotect
Sheets("Production Board").Select
Sheets("Production Board").copy Before:=Sheets(1)
Sheets("Production Board (2)").Select
On Error Resume Next
For Each ws In Worksheets
If (ws.Range("D4")) = "" Then
ws.Name = "Sheet" & ws.Index
Else
ws.Name = Format(ws.Range("D4"), "mm-dd-yyyy")
End If
Next
ActiveSheet.Shapes("Text Box 1").Select
Selection.delete
ActiveSheet.Shapes("Text Box 2").Select
Selection.delete
ActiveSheet.Shapes("Text Box 3").Select
Selection.delete
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
Sheets("Production Board").Select
Range("C6:I8,C10:I12,C14:I16,C21:I23").Select
Range("I21").Activate
Selection.ClearContents
Range("C6").Select
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
Sheets("Production Board").Select
End If
End Sub