ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Condensing Code (https://www.excelbanter.com/excel-programming/371273-condensing-code.html)

Steve

Condensing Code
 
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

Tom Ogilvy

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



All times are GMT +1. The time now is 09:16 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com