Hi. I'm new to the boards and would like to see about getting some help.
I'm writing a script to auto number a series of worksheets in the form of "Page xx of yy". Where xx is the current page and yy is the total number of pages. I have 2 main scripts doing this. My first script which is run as an addon is:
Private Sub Iteration()
Dim sht As Worksheet
Dim x1, x2, x3, x4 As String
Dim iter1, iter2 As String
On Error GoTo Errorcatch
iterform.Show
For Each sht In Sheets
sht.Range(iterform.iter2).Value = ActiveWorkbook.Sheets.Count
sht.Range(iterform.iter1).Value = sht.Index
Next sht
Exit Sub
Errorcatch:
MsgBox Err.Description
End Sub
This works perfectly. My problem is in my script I use to select the proper cells. I have a check to be sure that the cells entered are actually cells. If they are not, it tells the user to make the corrections. If the cell is inserted incorrectly, the sub-routine runs through again, BUT, it goes back to the If Then statement where the error occurred and gives the user error again, even if the cells were entered correctly. I'm checking that the first character is a letter and the second character is a number. The Code I used for this is:
Private Sub ok_Click()
If iterform.iter1 = "" Or iterform.iter2 = "" Then
iterform.Hide
MsgBox ("You have to enter cell coordinates.")
'iterform.Show
End If
If iterform.iter1 = iterform.iter2 Then
iterform.Hide
MsgBox ("The cells cannot be the same. Re-enter the cells properly.")
iterform.iter1.Value = ""
iterform.iter2.Value = ""
iterform.Show
End If
x1 = Left(iterform.iter2, 1)
x2 = Right(iterform.iter2, 1)
x3 = Left(iterform.iter1, 1)
x4 = Right(iterform.iter1, 1)
'ActiveSheet.Range("A1") = Asc(x1)
'ActiveSheet.Range("A2") = Asc(x2)
'ActiveSheet.Range("A3") = Asc(x3)
'ActiveSheet.Range("A4") = Asc(x4)
If Asc(x1) < 65 Or Asc(x1) > 90 Then
If Asc(x1) < 97 Or Asc(x1) > 122 Then
iterform.Hide
MsgBox ("There is a problem with one of the cells entered. Please check it before proceeding.")
iterform.iter1.Value = ""
iterform.iter2.Value = ""
' x1 = ""
' x2 = ""
' x3 = ""
' x4 = ""
iterform.Show
End If
End If
If Asc(x3) < 65 Or Asc(x3) > 90 Then
If Asc(x3) < 97 Or Asc(x3) > 122 Then
iterform.Hide
MsgBox ("There is a problem with one of the cells entered. Please check it before proceeding.")
iterform.iter1.Value = ""
iterform.iter2.Value = ""
' x1 = ""
' x2 = ""
' x3 = ""
' x4 = ""
iterform.Show
End If
End If
If Asc(x2) < 48 Or Asc(x2) > 57 Then
iterform.Hide
MsgBox ("There is a problem with one of the cells entered. Please check it before proceeding.")
iterform.iter1.Value = ""
iterform.iter2.Value = ""
' x1 = ""
' x2 = ""
' x3 = ""
' x4 = ""
iterform.Show
End If
If Asc(x4) < 48 Or Asc(x4) > 57 Then
iterform.Hide
MsgBox ("There is a problem with one of the cells entered. Please check it before proceeding.")
iterform.iter1.Value = ""
iterform.iter2.Value = ""
' x1 = ""
' x2 = ""
' x3 = ""
' x4 = ""
iterform.Show
End If
iterform.Hide
End Sub
Yes, I know it's ugly, but I'm still learning how to program so I'm pretty much fudging my way through it. I have a few parts of the script disabled, as I was trying a few things, but nothing was working.
Any help as to how to fix my program will be greatly appreciated.
Bookmarks