![]() |
option button dependant micro
I have created six macro that sort one of six columns (macro 1 sorts
column by column A, macro 2 sorts by column B, etc. I have created a user form (with option buttons) that allows the user to select if the sorting is Ascending (optAsc) or Descending (optDes), then select an option button (optDealer, optSig, optPO, optInv, optDate and optDue) to decide which of the 6 columns is actually sorted. (See code at bottom for one example.) I can not figure out how to make the action dependant upon which option button is selected. Any ideas? Sub alphabyDealerName() 'macro "Sheet1.alphabySignature" , sorts alphabetical by "Dealer Name(A2)" Range("Database").Select Selection.Sort Key1:=Range("A2"), Order1:=xlAscending, Header:=xlYes, _ OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _ DataOption1:=xlSortNormal End Sub (I know that I can change xlAscending to xlDescending to swap directions) TIA |
option button dependant micro
Is it dependant based on a checkbox, drop down, optionbutton? Sounds like a Select Case or a If Then is necessary. L Scholes Wrote: I have created six macro that sort one of six columns (macro 1 sorts column by column A, macro 2 sorts by column B, etc. I have created a user form (with option buttons) that allows the user to select if the sorting is Ascending (optAsc) or Descending (optDes), then select an option button (optDealer, optSig, optPO, optInv, optDate and optDue) to decide which of the 6 columns is actually sorted. (See code at bottom for one example.) I can not figure out how to make the action dependant upon which option button is selected. Any ideas? Sub alphabyDealerName() 'macro "Sheet1.alphabySignature" , sorts alphabetical by "Dealer Name(A2)" Range("Database").Select Selection.Sort Key1:=Range("A2"), Order1:=xlAscending, Header:=xlYes, _ OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _ DataOption1:=xlSortNormal End Sub (I know that I can change xlAscending to xlDescending to swap directions) TIA -- dok112 ------------------------------------------------------------------------ dok112's Profile: http://www.excelforum.com/member.php...o&userid=10581 View this thread: http://www.excelforum.com/showthread...hreadid=532420 |
option button dependant micro
Actually, my mistake. I didn't read the question fully. You can do If Then statement for the optionbuttons. Sub Test() If UserForm1.OptionButton1.value = True Then 'Response End If If UserForm1.OptionButton2.value = True Then 'Response End If End Sub Or a Select Case Statement can be used. Sub Test1() Select Case Value Case OptionButton1.Value = True 'Response Case OptionButton2.Value = True 'Response End Select End Sub dok112 Wrote: Is it dependant based on a checkbox, drop down, optionbutton? Sound like a Select Case or a If Then is necessary -- dok11 ----------------------------------------------------------------------- dok112's Profile: http://www.excelforum.com/member.php...fo&userid=1058 View this thread: http://www.excelforum.com/showthread.php?threadid=53242 |
option button dependant micro
I want this macro to fire when I select "optAsc" and "optSig." I'm new
to this and know that I should do the "Select Case" or "If/Then" arguments, but I dont know how to code it. Do you have an "If" example to fire this one? And an example of how to "Then" it so I can do both ways with this one macro? (If you can't tell, I know enough to understand what needs to happen, just new enough that I can't get 'er done!) TIA |
option button dependant micro
I have 6 "responses." Do I need to do this for all six, or the first 5
and "Else" the last? |
option button dependant micro
Actually I have another problem. I need two optionboxes selected: One
to determine Ascending or Descending for each of the 6 options. It looks like I need an "And" in there. (i.e., If optAsc = True AND optSig = True, then code above. If optDes = True AND optSig = True, the code above except xlDescending...etc. throughout 6 events, but only one fires, depending on the combination.) |
option button dependant micro
Actually I have another problem. I need two optionboxes selected: One
to determine Ascending or Descending for each of the 6 options. It looks like I need an "And" in there. (i.e., If optAsc = True AND optSig = True, then code above. If optDes = True AND optSig = True, the code above except xlDescending...etc. throughout 6 events, but only one fires, depending on the combination.) |
option button dependant micro
So you have 6 options, of which there are 4 that are individual choices and 2 that are together? Or is it different? I'm a little confused. -- dok112 ------------------------------------------------------------------------ dok112's Profile: http://www.excelforum.com/member.php...o&userid=10581 View this thread: http://www.excelforum.com/showthread...hreadid=532420 |
option button dependant micro
Try this and tell me if this is what you are looking for... Sub Test() If optAsc.Value = True And optSig.Value = True Then ' Your code for optAsc and optSig = True End If If optDes.Value = True And optSig.Value = True Then ' Your code for optDes and optSig = True End if ' Add any more combinations of them that you need here. End Sub L Scholes Wrote: Actually I have another problem. I need two optionboxes selected: One to determine Ascending or Descending for each of the 6 options. It looks like I need an "And" in there. (i.e., If optAsc = True AN optSig = True, then code above. If optDes = True AND optSig = True, the code above except xlDescending...etc. throughout 6 events, but only one fires, depending on the combination. -- dok11 ----------------------------------------------------------------------- dok112's Profile: http://www.excelforum.com/member.php...fo&userid=1058 View this thread: http://www.excelforum.com/showthread.php?threadid=53242 |
option button dependant micro
I have pasted my final code below and it works BEAUTIFULLY! Thank you
very much for your help. Private Sub cmdOK_Click() 'Dealer name If optAsc.Value = True And optDealer.Value = True Then Range("Database").Select Selection.Sort Key1:=Range("A2"), Order1:=xlAscending, Header:=xlYes, _ OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _ DataOption1:=xlSortNormal End If If optDes.Value = True And optDealer.Value = True Then Range("Database").Select Selection.Sort Key1:=Range("A2"), Order1:=xlDescending, Header:=xlYes, _ OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _ DataOption1:=xlSortNormal End If 'Signature If optAsc.Value = True And optSig.Value = True Then Range("Database").Select Selection.Sort Key1:=Range("B2"), Order1:=xlAscending, Header:=xlYes, _ OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _ DataOption1:=xlSortNormal End If If optDes.Value = True And optSig.Value = True Then Range("Database").Select Selection.Sort Key1:=Range("B2"), Order1:=xlDescending, Header:=xlYes, _ OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _ DataOption1:=xlSortNormal End If 'PO If optAsc.Value = True And optPO.Value = True Then Range("Database").Select Selection.Sort Key1:=Range("C2"), Order1:=xlAscending, Header:=xlYes, _ OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _ DataOption1:=xlSortNormal End If If optDes.Value = True And optPO.Value = True Then Range("Database").Select Selection.Sort Key1:=Range("C2"), Order1:=xlDescending, Header:=xlYes, _ OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _ DataOption1:=xlSortNormal End If 'Invoice If optAsc.Value = True And optInv.Value = True Then Range("Database").Select Selection.Sort Key1:=Range("D2"), Order1:=xlAscending, Header:=xlYes, _ OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _ DataOption1:=xlSortNormal End If If optDes.Value = True And optInv.Value = True Then Range("Database").Select Selection.Sort Key1:=Range("D2"), Order1:=xlDescending, Header:=xlYes, _ OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _ DataOption1:=xlSortNormal End If 'Date If optAsc.Value = True And optDate.Value = True Then Range("Database").Select Selection.Sort Key1:=Range("E2"), Order1:=xlAscending, Header:=xlYes, _ OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _ DataOption1:=xlSortNormal End If If optDes.Value = True And optDate.Value = True Then Range("Database").Select Selection.Sort Key1:=Range("E2"), Order1:=xlDescending, Header:=xlYes, _ OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _ DataOption1:=xlSortNormal End If 'Due Date If optAsc.Value = True And optDue.Value = True Then Range("Database").Select Selection.Sort Key1:=Range("F2"), Order1:=xlAscending, Header:=xlYes, _ OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _ DataOption1:=xlSortNormal End If If optDes.Value = True And optDue.Value = True Then Range("Database").Select Selection.Sort Key1:=Range("F2"), Order1:=xlDescending, Header:=xlYes, _ OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _ DataOption1:=xlSortNormal End If End Sub |
All times are GMT +1. The time now is 07:30 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com