Add worksheet

  • Thread starter Thread starter CAA
  • Start date Start date
C

CAA

Hello, Merry Christmas to you and a happy new year.

I am trying to add a worksheet template to a workbook if and when it is
needed. I don't seem to be able to get it right.
I cycle through about 12 rows on the first sheet, then 24 on the 2nd.
The 2nd sheet is identicle to the template i want to add. There may be
a far easier method here.
I would like to add the sheet when i've got to the end of sheet2, name
that sheet 3, 4 or 5? and put it to the end.

So far i've magaged this, but something's not right.

Private Sub Image11_Click()
N = N + 2
If N > 47 And sht = 1 Then
sht = 2: N = 6
ElseIf N > 52 And sht = 2 Then
sht = sht + 1: N = 6
End If

If Sheets.Count > sht And N >= 52 Then
Call Addsht
Else

End If
Label19.Caption = Sheets("Sheet" & sht).Cells(N, 1)
Call getinf

End Sub

Thanks for looking
CAA
 
If N > 47 And sht = 1 Then
sht = 2: N = 6
ElseIf N > 52 And sht = 2 Then
sht = sht + 1: N = 6
End If


You will never get to the "ElseIf N > 52" since the previously specified
condition "N > 47" p will already be met.

Perhaps you want the first condition to be "N > 47 And N <= 52" ?

HTH,
Shockley
 
Shockley,

The previous condition is If N>47 AND sht = 1
The ElseIf will be executed if sht = 2 (or more) even if N is >47.

HTH
Henry

shockley said:
If N > 47 And sht = 1 Then
sht = 2: N = 6
ElseIf N > 52 And sht = 2 Then
sht = sht + 1: N = 6
End If


You will never get to the "ElseIf N > 52" since the previously specified
condition "N > 47" p will already be met.

Perhaps you want the first condition to be "N > 47 And N <= 52" ?

HTH,
Shockley
 
Henry, thanks for catching that!

Regards,
Shockley


Henry said:
Shockley,

The previous condition is If N>47 AND sht = 1
The ElseIf will be executed if sht = 2 (or more) even if N is >47.

HTH
Henry
 
Back
Top