Condensing Code

G

Guest

I need help passing variables to another sub routine.
Below I have included a piece of code that would need to be repeated 12
times.
Let me know if i have to clarify anything!

The following items would have to be "swapped" out each time:
tbBlackASection1Weight
tbBlackASection1Description
BlackAContractPricePerPound
BlackAContractPrice


If QuoteBreakDown.tbBlackASection1Weight.Value <> "" Then
QuoteForm.Range("A" & DataRow).Value = "Black Uncoated " &
QuoteBreakDown.tbBlackASection1Description.Text
If Wizard.obShowWeights = True Then
QuoteForm.Range("E" & DataRow).Value = "Approximately"
With QuoteForm.Range("G" & DataRow)
.Value =
ThisWorkbook.Worksheets("Calculations").Range("BlackASection1Weight").Text &
" lbs @ "
.HorizontalAlignment = xlRight
End With
End If
If Wizard.obUnit = True Then
With QuoteForm.Range("H" & DataRow)
.Value = "$" &
Format(ThisWorkbook.Worksheets("Calculations").Range("BlackAContractPricePerPound").Value * 100, "##.#0") & " / cwt"
.HorizontalAlignment = xlRight
End With
End If
If Wizard.obLump = True Then
With QuoteForm.Range("H" & DataRow)
.Value = "$" &
ThisWorkbook.Worksheets("Calculations").Range("BlackAContractPrice").Value
.HorizontalAlignment = xlRight
End With
End If
DataRow = DataRow + 1
End If
 
G

Guest

Assume BlackA is the variable part.

Sub CalcSomething(aaa as String)


If QuoteBreakDown.controls( _
"tb" & aaa & "Section1Weight").Value <> "" Then


QuoteForm.Range("A" & DataRow).Value = _
"Black Uncoated " & QuoteBreakDown _
.Controls("tb" & aaa & _
"Section1Description").Text

If Wizard.obShowWeights = True Then
QuoteForm.Range("E" & DataRow).Value = "Approximately"
With QuoteForm.Range("G" & DataRow).Value = _
ThisWorkbook.Worksheets("Calculations") _
.Range(aaa & "Section1Weight").Text & _
" lbs @ "
.HorizontalAlignment = xlRight
End With
End If

If Wizard.obUnit = True Then
With QuoteForm.Range("H" & DataRow).Value = "$" & _
Format(ThisWorkbook.Worksheets("Calculations") _
.Range(aaa & "ContractPricePerPound") _
.Value * 100, "##.#0") & " / cwt"
.HorizontalAlignment = xlRight
End With
End If

If Wizard.obLump = True Then
With QuoteForm.Range("H" & DataRow).Value = "$" & _
ThisWorkbook.Worksheets("Calculations") _
.Range(aaa & "ContractPrice").Value
.HorizontalAlignment = xlRight
End With
End If

DataRow = DataRow + 1

End If
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top