O
omokeefe
I wrote 2 .vba subs, one to create a # of lines and create 3 check
boxes, and another to delete a number of lines and their check boxes.
This code works fine, but after a little while I"ll get the "Object
Library Invalid or contains references to object definitions that
could not be found" error. Any ideas how to fix?
Private Sub CommandButton1_Click()
Dim KeyWord As String
Dim iA As Integer
RowNum = Application.InputBox( _
Prompt:="Enter the Number of Rows to Create:", _
Title:="Create How Many?", Type:=1)
Cells(1, 1).Select
KeyWord = "AAAAA"
i = 1
Do While i < RowNum + 1
iA = 1
Set NameAddress = Cells.Find(What:=KeyWord, after:=ActiveCell,
LookIn:=xlValues, _
LookAt:=xlPart,
SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False)
NameAddress.Select
If NameAddress Is Nothing Then
MsgBox "Not found"
Else:
ActiveCell.Offset(-2, 0).Rows("1:1").EntireRow.Select
Selection.Copy
ActiveCell.Offset(1, 0).Rows("1:1").EntireRow.Select
Selection.Insert Shift:=xlDown
ActiveCell.Select
ActiveCell.Offset(0, 6).Select
Do While iA <= 3
top1 = ActiveCell.Top + 2
left1 = ActiveCell.Left + (ActiveCell.Width / 2) - 5
Set box1 =
ActiveSheet.OLEObjects.Add(ClassType:="Forms.CheckBox.1")
box1.Left = left1
box1.Top = top1
box1.Width = 16.5
box1.Height = 10.5
box1.Name = "boxA" & i * iA
ActiveCell.Offset(0, 2).Select
iA = iA + 1
Loop
End If
i = i + 1
Loop
End Sub
Private Sub CommandButton2_Click()
Dim KeyWord As String
Dim iA As Integer
DelNum = Application.InputBox( _
Prompt:="Enter the Number of Rows to Delete:", _
Title:="Delete How Many?", Type:=1)
Cells(1, 1).Select
KeyWord = "AAAAA"
i = 1
Do While i < DelNum + 1
iA = 1
Set NameAddress = Cells.Find(What:=KeyWord, after:=ActiveCell,
LookIn:=xlValues, _
LookAt:=xlPart,
SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False)
NameAddress.Select
If NameAddress Is Nothing Then
MsgBox "Not found"
Else:
ActiveCell.Offset(-2, 0).Rows("1:1").EntireRow.Select
Selection.Delete
ActiveCell.Select
ActiveCell.Offset(0, 6).Select
Do While iA <= 3
ActiveSheet.Shapes("boxA" & i * iA).Delete
iA = iA + 1
Loop
End If
i = i + 1
Loop
End Sub
boxes, and another to delete a number of lines and their check boxes.
This code works fine, but after a little while I"ll get the "Object
Library Invalid or contains references to object definitions that
could not be found" error. Any ideas how to fix?
Private Sub CommandButton1_Click()
Dim KeyWord As String
Dim iA As Integer
RowNum = Application.InputBox( _
Prompt:="Enter the Number of Rows to Create:", _
Title:="Create How Many?", Type:=1)
Cells(1, 1).Select
KeyWord = "AAAAA"
i = 1
Do While i < RowNum + 1
iA = 1
Set NameAddress = Cells.Find(What:=KeyWord, after:=ActiveCell,
LookIn:=xlValues, _
LookAt:=xlPart,
SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False)
NameAddress.Select
If NameAddress Is Nothing Then
MsgBox "Not found"
Else:
ActiveCell.Offset(-2, 0).Rows("1:1").EntireRow.Select
Selection.Copy
ActiveCell.Offset(1, 0).Rows("1:1").EntireRow.Select
Selection.Insert Shift:=xlDown
ActiveCell.Select
ActiveCell.Offset(0, 6).Select
Do While iA <= 3
top1 = ActiveCell.Top + 2
left1 = ActiveCell.Left + (ActiveCell.Width / 2) - 5
Set box1 =
ActiveSheet.OLEObjects.Add(ClassType:="Forms.CheckBox.1")
box1.Left = left1
box1.Top = top1
box1.Width = 16.5
box1.Height = 10.5
box1.Name = "boxA" & i * iA
ActiveCell.Offset(0, 2).Select
iA = iA + 1
Loop
End If
i = i + 1
Loop
End Sub
Private Sub CommandButton2_Click()
Dim KeyWord As String
Dim iA As Integer
DelNum = Application.InputBox( _
Prompt:="Enter the Number of Rows to Delete:", _
Title:="Delete How Many?", Type:=1)
Cells(1, 1).Select
KeyWord = "AAAAA"
i = 1
Do While i < DelNum + 1
iA = 1
Set NameAddress = Cells.Find(What:=KeyWord, after:=ActiveCell,
LookIn:=xlValues, _
LookAt:=xlPart,
SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False)
NameAddress.Select
If NameAddress Is Nothing Then
MsgBox "Not found"
Else:
ActiveCell.Offset(-2, 0).Rows("1:1").EntireRow.Select
Selection.Delete
ActiveCell.Select
ActiveCell.Offset(0, 6).Select
Do While iA <= 3
ActiveSheet.Shapes("boxA" & i * iA).Delete
iA = iA + 1
Loop
End If
i = i + 1
Loop
End Sub