Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
Change "Steel List" to "Steel" and "Members" to "Horizontals".
When you go into the VBA editor, (ALT+F11), you can insert a userform by clicking the Insert menu, then UserForm. The Controls toolbox should appear and you can hover over the combobox and it will have a tooltip that says ComboBox (not ListBox). Click on this. Then to insert it into the form, click once and hold it to mark the top left corner of the combobox, then move the mouse lower and to the right and release the button to mark the bottom right corner. Next, right click the ComboBox and click view code. It should bring you to a code form where you can paste this: Private Sub ComboBox1_Change() ActiveCell.Value = ComboBox1.Value UserForm1.Hide End Sub This will put whatever value you select into the active cell. You need to put the code I wrote above into a module, then go to the Excel menus and click Tools-Macro-Macros. Then select the macro "PopulateAcceptList" and click options. You can add a shortcut key here. Use something like semicolon or something else that isn't used already by Excel. So, my idea would be to go to the Horizontal sheet and put make the active cell on the line where all your data is for a particular horizontal. Then you could use the shortcut, (CTRL+;), and trigger the code. This would open up the userform with the combobox and allow you to select the appropriate steel for reinforcement. You'll need to understand the code so that you can modify it to make it work, however. Here's the code again with better comments. Option Explicit Public Sub PopulateAcceptList() Dim shtSteel As Worksheet, shtTestMember As Worksheet Dim lRow As Long Dim lCurrent As Long lCurrent = ActiveCell.Row Set shtSteel = Sheets("Steel") Set shtHorizontal = Sheets("Horizontal") 'first I'm setting variables for the two sheets since you need to compare values on both sheets in order to determine which steels will work. 'clear out old combobox items (we don't want steels that worked for the last horizontal already in the box, only the ones that we determine will work for this one) UserForm1.ComboBox1.Clear For lRow = 1 To shtSteel.UsedRange.Rows.Count 'calculations here to compare some calculation of the steel to 'what would be required for the member - it may be a combination of calculations from both sheets 'I added two variables, one from each sheet to show how this would work 'In this case, lRow is the row that we're currently looping through in order to determine if the steel will work 'lCurrent is the row of the horizontal that we're testing If shtSteel.Cells(lRow, 3) shtHorizontal.Cells(lCurrent, 4) Then 'this steel works - if it works, we add it to the combobox so that you can select it UserForm1.ComboBox1.AddItem shtSteel.Cells(lRow, 1).Value End If Next lRow 'after looping through all the possible steels and adding the ones that work, we display 'the form with the combobox UserForm1.Show End Sub |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Huge Apology - Multiple Posts In Error | Excel Discussion (Misc queries) | |||
Apologies for multiple posts | Excel Worksheet Functions | |||
Hellllllp Can,t remember pasword | Excel Worksheet Functions | |||
Unable to read own posts or replied Posts | Excel Discussion (Misc queries) | |||
Sorry for multiple posts... | Excel Discussion (Misc queries) |