How can one eliminate dupl code by passing variables in a CALL?

gigi46
04-28-2010, 10:08 PM
I currently have a program in which I have 4 subroutines that are called. The routines have the exact logic, except for the worksheet names it references and the ending number in the FOR statement (basically 4 variables - see colored fields below). Instead of having so much duplicate logic, is there a way to re-code the below routine to only have the logic repeated once ? Maybe I can pass it the correct parameters in the Call statement? Not sure how to do this. Any help is greatly appreciated?


Call Pool_vlookup_remaining_columns
Call Mat_vlookup_remaining_columns
Call Vol_vlookup_remaining_columns
Call Rates_vlookup_remaining_columns


Private Sub Pool_Vlookup_remaining_columns()

Sheets("Changes Pool").Select

Dim i As Integer
Dim j As Integer

FOR i = 4 To 37
j = i - 2

Cells(3, i).Formula = _
"=IF(ISNA(VLOOKUP('Cur Pool'!$C3,'Prior Pool'!$C$3:$AK$5000," & j & ",FALSE)),1," & _
"IF(VLOOKUP('Cur Pool'!$C3,'Prior Pool'!$C$3:$AK$5000," & j & ",FALSE)=" & _
"VLOOKUP('Cur Pool'!$C3,'Cur Pool'!$C$3:$AK$5000," & j & ",FALSE),0,1))"

Next i

Range("C3").Select
Range("C3:ak" & Sheets("Cur Pool").Range("b" & Rows.Count).End(xlUp).Row).FillDown
End Sub

--------------------------------------------------------------------------------

TerryTee
04-28-2010, 11:46 PM
Seems like you know which variables you need to pass, based on the color.
Here's a start with the sheet name to get you started.
Make sure you define the variables as the correct type.


Private Sub Pool_Vlookup_remaining_columns(ByVal sCurrSheet As String)
Dim i As Integer
Dim j As Integer

Sheets(sCurrSheet).Select
...
...
...
End Sub


-Terry

gigi46
04-30-2010, 09:17 AM
Sorry not still sure how to still go about coding this. I never passed variables before, so still very unclear. Can you provide more specifics to help me along?
Thanks.

gigi46
04-30-2010, 10:42 PM
This has been resloved.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum