Pookiemeister
Well-known Member
- Joined
- Jan 6, 2012
- Messages
- 626
- Office Version
- 365
- 2010
- Platform
- Windows
In my workbook I have seven sheets. Sheets four through seven contain values of product information for our four production lines.
The below code starts on sheet 4 and loops through each row of column B until it finds the value of the combobox located on the userform named Chattem or Chattemfrm.cmbPrdCde.Value. It then will select that cell containing that value and offset to obtain the new cells value and assign that value to the corresponding variable of either txtDz, txtCs, and txtUOM. These variables are needed for a formula located in on the Chattemfrm. Once the user clicks on the command button labeled Print or cmdPrint the formula is calculated. The txtbxdz.value comes from the Chattemfrm Userform.
An excerpt of the formula is below.
The problem that I am having is how do I pass the value of those integers inside my sub to be used inside the above formula located on Chattemfrm. I thought about possibly declaring those variables as Public but wasn't sure how to do that in this situation or maybe there might be a better way.
Thank you for any help offered.
The below code starts on sheet 4 and loops through each row of column B until it finds the value of the combobox located on the userform named Chattem or Chattemfrm.cmbPrdCde.Value. It then will select that cell containing that value and offset to obtain the new cells value and assign that value to the corresponding variable of either txtDz, txtCs, and txtUOM. These variables are needed for a formula located in on the Chattemfrm. Once the user clicks on the command button labeled Print or cmdPrint the formula is calculated. The txtbxdz.value comes from the Chattemfrm Userform.
An excerpt of the formula is below.
Code:
textValUp = ((txtbxdz.Value) / txtDz / txtCs) + 0.5 - 1E-16
The problem that I am having is how do I pass the value of those integers inside my sub to be used inside the above formula located on Chattemfrm. I thought about possibly declaring those variables as Public but wasn't sure how to do that in this situation or maybe there might be a better way.
Thank you for any help offered.
Code:
Option Explicit
Sub Test()
Dim ws_count, i, FinalRow, x, txtDz, txtCs As Integer
Dim txtUOM As String
ws_count = ActiveWorkbook.Worksheets.Count
For i = 4 To ws_count
Worksheets(i).Activate
FinalRow = Cells(Rows.Count, 2).End(xlUp).Row
For x = 1 To FinalRow
If Cells(x, 2) & " " & "(" & Cells(x, 3) & ")" = Chattemfrm.cmbPrdCde.Value Then
Cells(x, 2).Select
txtDz = Cells(x, 2).Offset(0, 2).Value
txtCs = Cells(x, 2).Offset(0, 3).Value
txtUOM = Cells(x, 2).Offset(0, 4).Value
End If
Next x
Next i
End Sub