G
Greg Maxey
Today I wrote some code to sequential number some Avery 5267 labels. My
template table has 7 columns and 20 rows (the Avery 5267 layout) for 80
labels. I knew that if I need more than 80 labels in the sequence then I
would need additional tables. I had a real tough time figuring out how many
tables I would actually need.
E.g. 81 + labels needs two tables, 161+ needs 3, etc.
Taking the required label count and dividing by 80 would give the base
number and then I would need one more if there was a remainder. I know
about INT returning the integer portion of a calculation result. Is there
something that returns the fractional part? What I ended up doing was
subtracting the integer part from the double and if result was > 0 then I
added another table. Is there a better way?
Dim tableCount as Long
Dim x as Double
labelCount = (seqEnd - seqStart) + 1
If labelCount > 80 Then
tablesCount = Int(labelCount / 80)
x = labelCount / 80
If x - tablesCount > 0 Then tablesCount = tablesCount + 1
If tablesCount > 1 Then
For i = 2 To tablesCount
oTbl.Range.Copy
Set oRng = ActiveDocument.Range
oRng.Collapse wdCollapseEnd
oRng.InsertBreak Type:=wdSectionBreakNextPage
ActiveDocument.Sections.Last.Range.Select
Selection.Paste
Next
End If
In a UserForm textbox I wanted to ensure that only numbers 0-9 could be
entered. I used:
Private Sub txtEndNum_Change()
Dim pStrTest
pStrTest = Right(Me.txtEndNum.Text, 1) 'the last key pressed entered.
If Len(Me.txtEndNum.Text) > 0 Then
If Not pStrTest Like "[0-9]" Then
Me.txtEndNum.Text = Left(Me.txtEndNum.Text, Len(Me.txtEndNum.Text) - 1)
End If
End If
End Sub
Is there a better way?
Thanks.
template table has 7 columns and 20 rows (the Avery 5267 layout) for 80
labels. I knew that if I need more than 80 labels in the sequence then I
would need additional tables. I had a real tough time figuring out how many
tables I would actually need.
E.g. 81 + labels needs two tables, 161+ needs 3, etc.
Taking the required label count and dividing by 80 would give the base
number and then I would need one more if there was a remainder. I know
about INT returning the integer portion of a calculation result. Is there
something that returns the fractional part? What I ended up doing was
subtracting the integer part from the double and if result was > 0 then I
added another table. Is there a better way?
Dim tableCount as Long
Dim x as Double
labelCount = (seqEnd - seqStart) + 1
If labelCount > 80 Then
tablesCount = Int(labelCount / 80)
x = labelCount / 80
If x - tablesCount > 0 Then tablesCount = tablesCount + 1
If tablesCount > 1 Then
For i = 2 To tablesCount
oTbl.Range.Copy
Set oRng = ActiveDocument.Range
oRng.Collapse wdCollapseEnd
oRng.InsertBreak Type:=wdSectionBreakNextPage
ActiveDocument.Sections.Last.Range.Select
Selection.Paste
Next
End If
In a UserForm textbox I wanted to ensure that only numbers 0-9 could be
entered. I used:
Private Sub txtEndNum_Change()
Dim pStrTest
pStrTest = Right(Me.txtEndNum.Text, 1) 'the last key pressed entered.
If Len(Me.txtEndNum.Text) > 0 Then
If Not pStrTest Like "[0-9]" Then
Me.txtEndNum.Text = Left(Me.txtEndNum.Text, Len(Me.txtEndNum.Text) - 1)
End If
End If
End Sub
Is there a better way?
Thanks.