Thread: Condensing Code
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 6,953
Default Condensing Code

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

--
Regards.
Tom Ogilvy


"steve" wrote:

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("Bla ckASection1Weight").Text &
" lbs @ "
.HorizontalAlignment = xlRight
End With
End If
If Wizard.obUnit = True Then
With QuoteForm.Range("H" & DataRow)
.Value = "$" &
Format(ThisWorkbook.Worksheets("Calculations").Ran ge("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("Bla ckAContractPrice").Value
.HorizontalAlignment = xlRight
End With
End If
DataRow = DataRow + 1
End If