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