Hi, everyone.
I'm working on a macro that compares values between two workbooks. I know the code to do the comparison is correct (I've used it on worksheets in the same workbook, but I'm having trouble making it work across workbooks). The code excerpt is below. Any assistance would be greatly appreciated. This is going to be done multiple times, which is why I'm setting it up as two subs (so I can later install loops, etc.)
Sub SelectionTool()
Dim oBook As Workbook
Dim nBook As Workbook
Set oBook = Workbooks("benchmark.xls"
Set nBook = Workbooks("hourly2.xls"
Call Mixer(12, Sheets("orgbrand-of", Sheets("orgbrand-of", "orgbrand-of", "L"
...
End Sub
Function Mixer(nItems As Integer, newSheet As Worksheet, oldSheet As Worksheet, newName As String, QuestionType As String)
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim l As Integer
Dim sig As Single
Dim benchFile As String
Dim oldValue As Integer
Dim newValue As Integer
Dim mult As Integer
Dim oBook As Workbook
Dim nBook As Workbook
sig = 0.105
nItems = 12
Set oBook = Workbooks("benchmark.xls"
Set nBook = Workbooks("hourly2.xls"
' pick and choose the variables to use
For i = 1 To nItems Step 1
j = i + 4
k = i + 1
nBook.Activate
newValue = newSheet.Range("G" & j & "".Value
newB = newSheet.Range("C" & j & "".Value
oBook.Activate
oldValue = oldSheet.Range("G" & j & "".Value
oldB = oldSheet.Range("C" & j & "".Value
sumB = newB + oldB
nBook.Activate
If newValue < sig Then
If oldValue < sig Then
oBook.Activate
oldSheet.Select
Range("B" & j & ":G" & j & "".Select
Selection.Copy
nBook.Activate
newSheet.Select
Range("I" & k & "".Select
ActiveSheet.Paste
Range("J" & k & "".Select
ActiveCell.FormulaR1C1 = sumB
Range("H" & k & "".Select
ActiveCell.FormulaR1C1 = "B"
ElseIf oldValue > sig Then
nBook.Activate
newSheet.Select
Range("B" & j & ":G" & j & "".Select
Selection.Copy
Range("I" & k & "".Select
ActiveSheet.Paste
Range("H" & k & "".Select
ActiveCell.FormulaR1C1 = "N"
End If
ElseIf newValue > sig Then
If oldValue < sig Then
oBook.Activate
oldSheet.Select
Range("B" & j & ":G" & j & "".Select
Selection.Copy
nBook.Activate
newBook.Select
Range("I" & k & "".Select
ActiveSheet.Paste
Range("H" & k & "".Select
ActiveCell.FormulaR1C1 = "O"
ElseIf oldValue > sig Then
nBook.Activate
newSheet.Select
Range("B" & j & ":G" & j & "".Select
Selection.Copy
Range("I" & k & "".Select
ActiveSheet.Paste
Range("J" & k & "".Select
ActiveCell.FormulaR1C1 = "0"
Range("N" & k & "".Select
ActiveCell.FormulaR1C1 = ".99"
Range("H" & k & "".Select
ActiveCell.FormulaR1C1 = "0"
End If
End If
Next i
End Function
Any help would be greatly appreciated.
Thanks,
Aaron
I'm working on a macro that compares values between two workbooks. I know the code to do the comparison is correct (I've used it on worksheets in the same workbook, but I'm having trouble making it work across workbooks). The code excerpt is below. Any assistance would be greatly appreciated. This is going to be done multiple times, which is why I'm setting it up as two subs (so I can later install loops, etc.)
Sub SelectionTool()
Dim oBook As Workbook
Dim nBook As Workbook
Set oBook = Workbooks("benchmark.xls"
Set nBook = Workbooks("hourly2.xls"
Call Mixer(12, Sheets("orgbrand-of", Sheets("orgbrand-of", "orgbrand-of", "L"
...
End Sub
Function Mixer(nItems As Integer, newSheet As Worksheet, oldSheet As Worksheet, newName As String, QuestionType As String)
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim l As Integer
Dim sig As Single
Dim benchFile As String
Dim oldValue As Integer
Dim newValue As Integer
Dim mult As Integer
Dim oBook As Workbook
Dim nBook As Workbook
sig = 0.105
nItems = 12
Set oBook = Workbooks("benchmark.xls"
Set nBook = Workbooks("hourly2.xls"
' pick and choose the variables to use
For i = 1 To nItems Step 1
j = i + 4
k = i + 1
nBook.Activate
newValue = newSheet.Range("G" & j & "".Value
newB = newSheet.Range("C" & j & "".Value
oBook.Activate
oldValue = oldSheet.Range("G" & j & "".Value
oldB = oldSheet.Range("C" & j & "".Value
sumB = newB + oldB
nBook.Activate
If newValue < sig Then
If oldValue < sig Then
oBook.Activate
oldSheet.Select
Range("B" & j & ":G" & j & "".Select
Selection.Copy
nBook.Activate
newSheet.Select
Range("I" & k & "".Select
ActiveSheet.Paste
Range("J" & k & "".Select
ActiveCell.FormulaR1C1 = sumB
Range("H" & k & "".Select
ActiveCell.FormulaR1C1 = "B"
ElseIf oldValue > sig Then
nBook.Activate
newSheet.Select
Range("B" & j & ":G" & j & "".Select
Selection.Copy
Range("I" & k & "".Select
ActiveSheet.Paste
Range("H" & k & "".Select
ActiveCell.FormulaR1C1 = "N"
End If
ElseIf newValue > sig Then
If oldValue < sig Then
oBook.Activate
oldSheet.Select
Range("B" & j & ":G" & j & "".Select
Selection.Copy
nBook.Activate
newBook.Select
Range("I" & k & "".Select
ActiveSheet.Paste
Range("H" & k & "".Select
ActiveCell.FormulaR1C1 = "O"
ElseIf oldValue > sig Then
nBook.Activate
newSheet.Select
Range("B" & j & ":G" & j & "".Select
Selection.Copy
Range("I" & k & "".Select
ActiveSheet.Paste
Range("J" & k & "".Select
ActiveCell.FormulaR1C1 = "0"
Range("N" & k & "".Select
ActiveCell.FormulaR1C1 = ".99"
Range("H" & k & "".Select
ActiveCell.FormulaR1C1 = "0"
End If
End If
Next i
End Function
Any help would be greatly appreciated.
Thanks,
Aaron