Jim and Bob,
Thanks for the replies.
Jim you surmised correctly, the optionbuttons are embedded on the sheet
and they are from the control toolbox. Sorry, I should have included
that in my OP. I tried your exercise and the msgboxes worked as
advertised, however when applying the method to my routine I am still
getting the same error.
Bob I tried your suggestion and got a different error message:
Run-time error 5
Invalid proceedure caller arguement. again a new error for me.
Here is my code with the Dim statements and Bob's suggestions commented
out.
Sub Import_CWR_SUBCON_COSTS_To_SubConCO()
Dim Wks1 As Worksheet
Dim Wks3 As Worksheet
Dim CopyRow As Long
Dim Entries As Long
Dim i As Long
Dim N As Long
Dim Cnt As Integer
Dim Msg As Integer
Dim Response As Integer
'Dim OptionButton1 As Object '<<<<<<<<< Not sure this is correct
'Dim OptionButton2 As Object '<<<<<<<<< Not sure this is correct
Dim Opt1 As Boolean
Dim Opt2 As Boolean
Msg = MsgBox("Have you double checked the SUB CO NO: and that the same
SUB CO NO:" _
& " has been entered in the appropriate cell of the CWR Log for each"
_
& " CWR you want to make part of this Subcontractor Change Order ?", _
vbYesNo + vbQuestion, "Import CWRs to Subcontractor Change Order by SUB
CO NO:")
If Msg = 6 Then
Application.ScreenUpdating = False
Set Wks1 = Worksheets("CWR LOG")
Set Wks3 = ActiveSheet
Opt1 = Wks3.OptionButton1.Value '<<<<<<<Compile Error
Opt2 = Wks3.OptionButton2.Value '<<<<<<<Compile Error
'Opt1 = Wks3.OLEObjects(OptionButton1).Object.Value '<<<<<<<Run-time
error 5
'Opt2 = Wks3.OLEObjects(OptionButton2).Object.Value '<<<<<<<Run-time
error 5
Wks3.Range("SubCon_Entry_Range").ClearContents
CopyRow = 30
Entries = Excel.WorksheetFunction.CountA(Wks1.Range("B:B"))
Cnt = 0
For i = 9 To Entries + 100
N = Wks1.Cells(i, 2).Value
If N = Range("SubCon_CHANGE_ORDER_NO") Then Cnt = Cnt + 1
If Cnt 15 Then
Msg = MsgBox("You are attempting to import more than 15 CWR
records. Only the First 15 Records will be pasted. Please return to the
CWR Log Page and reduce the number of CWRs you want to make part of
this Change Order to 15 or less. Then hit the Import Subcontractor
Costs from CWR's button again.", vbOKOnly + vbCritical, "Exceeded
number of Records")
If Response = 1 Or 2 Then
Exit Sub
End If
ElseIf N = Range("SubCon_CHANGE_ORDER_NO") And Cnt <= 15 _
And Opt1 = 1 Then
With Wks3
..Unprotect ("geekk")
..Cells(CopyRow, 2).Value = Wks1.Cells(i, 3).Value
..Cells(CopyRow, 3).Value = Wks1.Cells(i, 1).Value
..Cells(CopyRow, 4).Value = Wks1.Cells(i, 4).Value
..Cells(CopyRow, 5).Value = Wks1.Cells(i, 6).Value
..Protect ("geekk")
End With
CopyRow = CopyRow + 1
ElseIf N = Range("SubCon_CHANGE_ORDER_NO") And Cnt <= 15 _
And Opt2 = 1 Then
With Wks3
..Unprotect ("geekk")
..Cells(CopyRow, 2).Value = Wks1.Cells(i, 3).Value
..Cells(CopyRow, 3).Value = Wks1.Cells(i, 1).Value
..Cells(CopyRow, 4).Value = Wks1.Cells(i, 4).Value
..Cells(CopyRow, 5).Value = Wks1.Cells(i, 7).Value
..Protect ("geekk")
End With
CopyRow = CopyRow + 1
End If
Next i
Wks3.Range("L5").Activate
Application.ScreenUpdating = True
End If
If Msg = 7 Then
Exit Sub
End If
End Sub
--
Casey
------------------------------------------------------------------------
Casey's Profile:
http://www.excelforum.com/member.php...fo&userid=4545
View this thread:
http://www.excelforum.com/showthread...hreadid=540756