How make code dynamic (I think)

Pookiemeister

Well-known Member
Joined
Jan 6, 2012
Messages
626
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
On a spreadsheet I have the names of five columns that contain the title of Product Codes, Product Description, Dozens per case, Cases per pallet and UOM(Unit of Measure). As of now, on my user form, I have a combo box that the user will select the product, a command button, and a text box. The values of that combo box are populated from the spreadsheet with code. The product Code is located in Column B (starts in B3 to be exact), Product Description located in Column C (starts in C3 to be exact), Product Description located in Column C (starts in C3 to be exact), Dozens per case in Column D (starts in D3 to be exact), Cases per pallet in Column E (starts in E3 to be exact), and finally Dozens per case in Column F (starts in F3 to be exact). Once the user selects the product from the combo box and enters a value in the text box(called "txtbxdz") and clicks the command button. A formula will be performed. Currently the values are hard coded into the program as shown in the formula below. I hope my explanation makes sense. Thank You.
<code style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; vertical-align: baseline; box-sizing: inherit; white-space: inherit;">
Code:
<code style="font-style: inherit; font-variant: inherit; font-weight: inherit; white-space: inherit; margin: 0px; padding: 0px; border: 0px; font-stretch: inherit; line-height: inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; vertical-align: baseline; box-sizing: inherit;">[COLOR=#101094][FONT=inherit]Private [/FONT][/COLOR][COLOR=#101094][FONT=inherit]Sub[/FONT][/COLOR][COLOR=#303336][FONT=inherit] cmdbtnPrint_Click[/FONT][/COLOR][COLOR=#303336][FONT=inherit]()[/FONT][/COLOR][COLOR=#303336][FONT=inherit]
[/FONT][/COLOR][COLOR=#101094][FONT=inherit]Dim[/FONT][/COLOR][COLOR=#303336][FONT=inherit] textValUp [/FONT][/COLOR][COLOR=#101094][FONT=inherit]As[/FONT][/COLOR][COLOR=#101094][FONT=inherit]Long[/FONT][/COLOR][COLOR=#303336][FONT=inherit]
[/FONT][/COLOR][COLOR=#101094][FONT=inherit]Dim[/FONT][/COLOR][COLOR=#303336][FONT=inherit] textValDown [/FONT][/COLOR][COLOR=#101094][FONT=inherit]As[/FONT][/COLOR][COLOR=#101094][FONT=inherit]Long[/FONT][/COLOR][COLOR=#303336][FONT=inherit]
[/FONT][/COLOR][COLOR=#101094][FONT=inherit]Dim[/FONT][/COLOR][COLOR=#303336][FONT=inherit] txtUOM [/FONT][/COLOR][COLOR=#101094][FONT=inherit]As[/FONT][/COLOR][COLOR=#101094][FONT=inherit]String[/FONT][/COLOR][COLOR=#303336][FONT=inherit]
[/FONT][/COLOR][COLOR=#101094][FONT=inherit]Dim[/FONT][/COLOR][COLOR=#303336][FONT=inherit] txtCs [/FONT][/COLOR][COLOR=#101094][FONT=inherit]As[/FONT][/COLOR][COLOR=#101094][FONT=inherit]Long[/FONT][/COLOR][COLOR=#303336][FONT=inherit]
[/FONT][/COLOR][COLOR=#101094][FONT=inherit]Dim[/FONT][/COLOR][COLOR=#303336][FONT=inherit] txtDz [/FONT][/COLOR][COLOR=#101094][FONT=inherit]As[/FONT][/COLOR][COLOR=#101094][FONT=inherit]Long[/FONT][/COLOR][COLOR=#303336][FONT=inherit]

    [/FONT][/COLOR][COLOR=#101094][FONT=inherit]Case[/FONT][/COLOR][COLOR=#101094][FONT=inherit]Is[/FONT][/COLOR][COLOR=#303336][FONT=inherit]=[/FONT][/COLOR][COLOR=#7D2727][FONT=inherit]"4120-5-01 (ALLERGY 180MG 5CT)"[/FONT][/COLOR][COLOR=#303336][FONT=inherit]
        txtDz [/FONT][/COLOR][COLOR=#303336][FONT=inherit]=[/FONT][/COLOR][COLOR=#7D2727][FONT=inherit]2[/FONT][/COLOR][COLOR=#303336][FONT=inherit]
        txtCs [/FONT][/COLOR][COLOR=#303336][FONT=inherit]=[/FONT][/COLOR][COLOR=#7D2727][FONT=inherit]200[/FONT][/COLOR][COLOR=#303336][FONT=inherit]
        txtUOM [/FONT][/COLOR][COLOR=#303336][FONT=inherit]=[/FONT][/COLOR][COLOR=#7D2727][FONT=inherit]"DZ"[/FONT][/COLOR][COLOR=#303336][FONT=inherit]
[/FONT][/COLOR][COLOR=#101094][FONT=inherit]End[/FONT][/COLOR][COLOR=#101094][FONT=inherit]Select[/FONT][/COLOR][COLOR=#303336][FONT=inherit]

textValUp [/FONT][/COLOR][COLOR=#303336][FONT=inherit]=[/FONT][/COLOR][COLOR=#303336][FONT=inherit](([/FONT][/COLOR][COLOR=#303336][FONT=inherit]txtbxdz[/FONT][/COLOR][COLOR=#303336][FONT=inherit].[/FONT][/COLOR][COLOR=#303336][FONT=inherit]Value[/FONT][/COLOR][COLOR=#303336][FONT=inherit])[/FONT][/COLOR][COLOR=#303336][FONT=inherit]/[/FONT][/COLOR][COLOR=#303336][FONT=inherit] txtDz [/FONT][/COLOR][COLOR=#303336][FONT=inherit]/[/FONT][/COLOR][COLOR=#303336][FONT=inherit] txtCs[/FONT][/COLOR][COLOR=#303336][FONT=inherit])[/FONT][/COLOR][COLOR=#303336][FONT=inherit]+[/FONT][/COLOR][COLOR=#7D2727][FONT=inherit]0.5[/FONT][/COLOR][COLOR=#303336][FONT=inherit]-[/FONT][/COLOR][COLOR=#7D2727][FONT=inherit]1E-16[/FONT][/COLOR][COLOR=#303336][FONT=inherit]
textValDown [/FONT][/COLOR][COLOR=#303336][FONT=inherit]=[/FONT][/COLOR][COLOR=#303336][FONT=inherit](([/FONT][/COLOR][COLOR=#303336][FONT=inherit]txtbxdz[/FONT][/COLOR][COLOR=#303336][FONT=inherit].[/FONT][/COLOR][COLOR=#303336][FONT=inherit]Value[/FONT][/COLOR][COLOR=#303336][FONT=inherit])[/FONT][/COLOR][COLOR=#303336][FONT=inherit]/[/FONT][/COLOR][COLOR=#303336][FONT=inherit] txtDz [/FONT][/COLOR][COLOR=#303336][FONT=inherit]/[/FONT][/COLOR][COLOR=#303336][FONT=inherit] txtCs[/FONT][/COLOR][COLOR=#303336][FONT=inherit])[/FONT][/COLOR][COLOR=#303336][FONT=inherit]-[/FONT][/COLOR][COLOR=#7D2727][FONT=inherit]0.5[/FONT][/COLOR][COLOR=#303336][FONT=inherit]+[/FONT][/COLOR][COLOR=#7D2727][FONT=inherit]1E-16[/FONT][/COLOR]</code>

</code>
 
Then they probably don't use it but the errors are in the file containd in this zip MrExcel HTML Maker 20170807.zip
 
Upvote 0

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
I've just downloaded that add-in & it works fine for me.
I did a test post here to make sure
 
Upvote 0
Try compiling the vba code and run it if there is no file selected.
Troubleshooting is my field of work as well as writing code and testing applications with VBA.
 
Upvote 0
I am re-asking the question. After reviewing what I previously typed. I noticed some minor errors in my explanation. So let me try this again. For starters, perhaps a better title should of been: "How to pull numbers from a spreadsheet that will be used in a formula". This explanation is more the same as the other with the exception of the mention of the UOM(unit of measure) located in clolumn F(F3 to be exact). Sorry and thank you.
Code:
[TABLE="width: 64"]
 <colgroup><col width="64" style="width:48pt"> </colgroup><tbody>[TR]
  [TD="class: xl64, width: 64"]Private Sub cmdbtnPrint_Click()[/TD]
 [/TR]
 [TR]
  [TD="class: xl65"]Dim textValUp AsLong[/TD]
 [/TR]
 [TR]
  [TD="class: xl65"]Dim textValDown AsLong[/TD]
 [/TR]
 [TR]
  [TD="class: xl65"]Dim txtUOM AsString[/TD]
 [/TR]
 [TR]
  [TD="class: xl65"]Dim txtCs AsLong[/TD]
 [/TR]
 [TR]
  [TD="class: xl65"]Dim txtDz AsLong[/TD]
 [/TR]
 [TR]
  [TD="class: xl66"][/TD]
 [/TR]
 [TR]
  [TD="class: xl67"]CaseIs="4120-5-01  (ALLERGY 180MG 5CT)"[/TD]
 [/TR]
 [TR]
  [TD="class: xl67"]    txtDz =2[/TD]
 [/TR]
 [TR]
  [TD="class: xl67"]    txtCs =200[/TD]
 [/TR]
 [TR]
  [TD="class: xl67"]    txtUOM ="DZ"[/TD]
 [/TR]
 [TR]
  [TD="class: xl65"]End Select[/TD]
 [/TR]
 [TR]
  [TD="class: xl66"][/TD]
 [/TR]
 [TR]
  [TD="class: xl67"]textValUp =((txtbxdz.Value)/  txtDz / txtCs)+0.5-1E-16 [/TD]
 [/TR]
 [TR]
  [TD="class: xl68"]textValDown =((txtbxdz.Value)/ txtDz / txtCs)-0.5+1E-16[/TD]
[/TR]
</tbody>[/TABLE]
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top