Hi, everyone.
I'm in the process of writing a macro that basically handles a decisions tree. I've got data like this:
In excel file "Test1.xls"
Name B Sig
Rent .25 .01
Own 1.2 .15
Parents .22 .78
In excel file "Test2.xls"
Name B Sig
Rent - D .15 .20
Own - D .22 .05
Parents -D .19 .22
What I want to be able to do is go into file Test2.xls and run a macro that does the following
If column "sig", row A in test1.xls < .105 and column "sig, row A in test2.xls < .105, then add both B's.
If column "sig", row A in test1.xls > .105 and column "sig", row A in test 2.xls <.105, then use the B from test 2.xls.
If column "sig", row A in test1.xls > .105 and column "sig, row A in test2.xls > .105, then put a 0.
If column "sig", row A in test1.xls > .105 and column "sig", row A in test 2.xls <.105, then use the B from test 1.xls.
I'm first not sure how to access the external file and then how to perform the complicated If statements. I considered doing something like this (this is pseudocode and doesn't work):
Sub SelectionTool()
Dim nItems As Integer
Dim i As Integer
Dim j As Integer
Dim sig As Integer
Dim benchFile As String
' set universal constants
sig = 0.105
nItems = 12
benchFile = "bench_test.xls"
With Worksheet("orgbrand-of"
For i = 1 To nItems Step 1
j = i + 4
oldValue = Application.WorksheetFunction.VLookup(.Range("A" & j & ""
, "[" & benchFile & "]'worksheet'!R2C1:R10:C4", 2, False)
newValue = .Range("G" & j & ""
.Value
If newValue < sig Then
If oldValue < sig Then
Range("X" & j & ""
.Select
ActiveCell.FormulaR1C1 = newValue + oldValue
Else
Range("X" & j & ""
.Select
ActiveCell.FormulaR1C1 = newValue
End If
Else
If oldValue < sig Then
Range("X" & j & ""
.Select
ActiveCell.FormulaR1C1 = oldValue
Else
Range("X" & j & ""
.Select
ActiveCell.FormulaR1C1 = "0"
End If
End If
Next i
Any ideas?
I'm in the process of writing a macro that basically handles a decisions tree. I've got data like this:
In excel file "Test1.xls"
Name B Sig
Rent .25 .01
Own 1.2 .15
Parents .22 .78
In excel file "Test2.xls"
Name B Sig
Rent - D .15 .20
Own - D .22 .05
Parents -D .19 .22
What I want to be able to do is go into file Test2.xls and run a macro that does the following
If column "sig", row A in test1.xls < .105 and column "sig, row A in test2.xls < .105, then add both B's.
If column "sig", row A in test1.xls > .105 and column "sig", row A in test 2.xls <.105, then use the B from test 2.xls.
If column "sig", row A in test1.xls > .105 and column "sig, row A in test2.xls > .105, then put a 0.
If column "sig", row A in test1.xls > .105 and column "sig", row A in test 2.xls <.105, then use the B from test 1.xls.
I'm first not sure how to access the external file and then how to perform the complicated If statements. I considered doing something like this (this is pseudocode and doesn't work):
Sub SelectionTool()
Dim nItems As Integer
Dim i As Integer
Dim j As Integer
Dim sig As Integer
Dim benchFile As String
' set universal constants
sig = 0.105
nItems = 12
benchFile = "bench_test.xls"
With Worksheet("orgbrand-of"
For i = 1 To nItems Step 1
j = i + 4
oldValue = Application.WorksheetFunction.VLookup(.Range("A" & j & ""
newValue = .Range("G" & j & ""
If newValue < sig Then
If oldValue < sig Then
Range("X" & j & ""
ActiveCell.FormulaR1C1 = newValue + oldValue
Else
Range("X" & j & ""
ActiveCell.FormulaR1C1 = newValue
End If
Else
If oldValue < sig Then
Range("X" & j & ""
ActiveCell.FormulaR1C1 = oldValue
Else
Range("X" & j & ""
ActiveCell.FormulaR1C1 = "0"
End If
End If
Next i
Any ideas?