![]() |
Use optionbutton value to select code to run.
Hi, I have sheet that imports data from another sheet via a comand button The sheet also has two option buttons. What I am attempting to do i import slighty different information from the other sheet depending o which optionbutton is selected. (There is code behind the optio buttons to insure only one can be chosen at a time.) I am getting the following error message: Compile Error: Method or Data Member not found. This is a new error message for me and nothing in Help is given me an more ideas to try. Here is my Code: Option Explicit 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 sam 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 SU 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 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 CW records. Only the First 15 Records will be pasted. Please return to th CWR Log Page and reduce the number of CWRs you want to make part o this Change Order to 15 or less. Then hit the Import Subcontracto Costs from CWR's button again.", vbOKOnly + vbCritical, "Exceede 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 = True 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 = True 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 Su -- Case ----------------------------------------------------------------------- Casey's Profile: http://www.excelforum.com/member.php...nfo&userid=454 View this thread: http://www.excelforum.com/showthread.php?threadid=54075 |
Use optionbutton value to select code to run.
Maybe try
Opt1= Wks.OLEObjects("OptionButton1").Object.Value -- HTH Bob Phillips (remove xxx from email address if mailing direct) "Casey" wrote in message ... Hi, I have sheet that imports data from another sheet via a comand button. The sheet also has two option buttons. What I am attempting to do is import slighty different information from the other sheet depending on which optionbutton is selected. (There is code behind the option buttons to insure only one can be chosen at a time.) I am getting the following error message: Compile Error: Method or Data Member not found. This is a new error message for me and nothing in Help is given me any more ideas to try. Here is my Code: Option Explicit 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 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 = True 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 = True 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 |
Use optionbutton value to select code to run.
The option buttons are embedded in the sheet I presume. My question is what
kind of buttons are they? Are they from the control toolbox or are they from the forms toolbar? If they are from the control toolbox then you can read the values very sismiar to what you have. You just need to delete the dim statements for the option buttons. Try this to see what I mean. In a new workbook on sheet1 add two option buttons from the control toolbar (don't rename the buttons). Select one of the option buttons. In the VBE add a standard code module and add the following code to it Sub test() MsgBox Sheet1.OptionButton1.Value MsgBox Sheet1.OptionButton2.Value End Sub -- HTH... Jim Thomlinson "Casey" wrote: Hi, I have sheet that imports data from another sheet via a comand button. The sheet also has two option buttons. What I am attempting to do is import slighty different information from the other sheet depending on which optionbutton is selected. (There is code behind the option buttons to insure only one can be chosen at a time.) I am getting the following error message: Compile Error: Method or Data Member not found. This is a new error message for me and nothing in Help is given me any more ideas to try. Here is my Code: Option Explicit 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 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 = True 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 = True 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 |
Use optionbutton value to select code to run.
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 |
Use optionbutton value to select code to run.
Bob, I apologize, looking again at you code I see I neglected to include th "" for the OptionButton names. I retried your code after correcting tha oversight and it works beautifully. Many thanks for the help -- Case ----------------------------------------------------------------------- Casey's Profile: http://www.excelforum.com/member.php...nfo&userid=454 View this thread: http://www.excelforum.com/showthread.php?threadid=54075 |
Use optionbutton value to select code to run.
I guessed correctly than it was control toolbox <G
-- HTH Bob Phillips (remove xxx from email address if mailing direct) "Casey" wrote in message ... Bob, I apologize, looking again at you code I see I neglected to include the "" for the OptionButton names. I retried your code after correcting that oversight and it works beautifully. Many thanks for the help. -- Casey ------------------------------------------------------------------------ Casey's Profile: http://www.excelforum.com/member.php...fo&userid=4545 View this thread: http://www.excelforum.com/showthread...hreadid=540756 |
All times are GMT +1. The time now is 12:23 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com