H
hamad.fatima
I have 10 different files and 1 master file. I want to add few cells
from the individual file to my master file. I have a macro but it
brings back the values from the specified ranges, does not add
anything. Is ther a way to change this macro to hep add few
cells.....-------here is the macro i have
Public Sub UPDATE_FORECAST_06()
On Error Resume Next
Dim objBook As Excel.Workbook
Dim intLoop As Integer
If (Workbooks.Count > 1) Then
MsgBox "Please close all workbooks except the 4 WAY MATCH -2006
workbook and try again.", vbInformation, "4 WAY MATCH"
Else
With Workbooks(1).Worksheets("FCT REF")
ClearTotals
Do While True
intLoop = intLoop + 1
If (Trim(.Cells(intLoop, 1)) <> "") Then
Set objBook = Workbooks.Open(.Cells(intLoop, 1),
False, , , .Cells(intLoop, 2))
' tester1 = Trim(.Cells(intLoop, 1))
' 'tester2 = Trim(.Cells(intLoop, 2))
' Stop
If (objBook Is Nothing) Then
.Cells(intLoop, 3) = "Failed - " &
Err.Description
Else
ProcessOperatingActual
ProcessOperatingPlan
'ProcessForecastedPLAN
'ProcessProjectCapitalPlan
' Stop
objBook.Saved = True
objBook.Close
.Cells(intLoop, 3) = "Succeeded"
End If
Set objBook = Nothing
Else
Exit Do
End If
Loop
MsgBox "Finished", vbInformation, "Summary"
End With
End If
On Error GoTo 0
End Sub
Private Sub ProcessOperatingActual()
' Set objSheet1 = Workbooks(1).Worksheets(2)
' Set objSheet2 = Workbooks(2).Worksheets(2)
ProcessRange 6, 8, 4, 27
' Where 6 and 8 reperesent rows & 4, 24 represent columns
ProcessRange 12, 16, 4, 27
ProcessRange 20, 23, 4, 27
ProcessRange 27, 31, 4, 27
ProcessRange 37, 39, 4, 27
ProcessRange 43, 44, 4, 27
ProcessRange 48, 61, 4, 27
ProcessRange 67, 75, 4, 27
Set objSheet1 = Nothing
Set objSheet2 = Nothing
End Sub
Private Sub ProcessOperatingPlan()
' Set objSheet1 = Workbooks(1).Worksheets(3)
'Set objSheet2 = Workbooks(2).Worksheets(3)
ProcessRange2 8, 10, 4, 15
ProcessRange2 14, 18, 4, 15
ProcessRange2 22, 25, 4, 15
ProcessRange2 29, 33, 4, 15
ProcessRange2 39, 41, 4, 15
ProcessRange2 45, 46, 4, 15
ProcessRange2 50, 63, 4, 15
ProcessRange2 69, 77, 4, 15
Set objSheet1 = Nothing
Set objSheet2 = Nothing
End Sub
' Private Sub ProcessForecastedPLAN()
'Set objSheet1 = Workbooks(1).Worksheets(3)
'
'Set objSheet2 = Workbooks(2).Worksheets(3)
' ProcessRange 5, 7, 4, 15
' ProcessRange 11, 17, 4, 15
'ProcessRange 21, 24, 4, 15
'ProcessRange 28, 33, 4, 15
'ProcessRange 39, 44, 4, 15
'ProcessRange 48, 49, 4, 15
'ProcessRange 53, 71, 4, 15
'ProcessRange 75, 83, 4, 15
'ProcessRange 89, 101, 4, 15
' Set objSheet2 = Nothing
'End Sub
'Private Sub ProcessProjectCapitalPlan()
' Set objSheet1 = Workbooks(1).Worksheets(5)
'Set objSheet2 = Workbooks(2).Worksheets(5)
'ProcessRange 5, 7, 4, 15
' ProcessRange 11, 17, 4, 15
' ProcessRange 21, 24, 4, 15
'ProcessRange 28, 33, 4, 15
'ProcessRange 39, 44, 4, 15
'ProcessRange 48, 49, 4, 15
'ProcessRange 53, 71, 4, 15
'ProcessRange 75, 83, 4, 15
'ProcessRange 89, 101, 4, 1
'Set objSheet1 = Nothing
' Set objSheet2 = Nothing
'End Sub
Private Sub ProcessRange(ByVal StartRow As Integer, ByVal EndRow As
Integer, ByVal StartColumn As Integer, ByVal EndColumn As Integer)
Dim intRow As Integer
Dim intCol As Integer
For intRow = StartRow To EndRow
For intCol = StartColumn To EndColumn
Workbooks(1).Worksheets(2).Cells(intRow, intCol).Value =
Workbooks(1).Worksheets(2).Cells(intRow, intCol).Value +
Workbooks(2).Worksheets(2).Cells(intRow, intCol).Value
' Stop
' objSheet1.Cells(intRow, intCol).Value =
objSheet1.Cells(intRow, intCol).Value + objSheet2.Cells(intRow,
intCol).Value
Next
Next
End Sub
Private Sub ProcessRange2(ByVal StartRow As Integer, ByVal EndRow As
Integer, ByVal StartColumn As Integer, ByVal EndColumn As Integer)
Dim intRow As Integer
Dim intCol As Integer
For intRow = StartRow To EndRow
For intCol = StartColumn To EndColumn
' Stop
Workbooks(1).Worksheets(3).Cells(intRow, intCol).Value =
Workbooks(1).Worksheets(3).Cells(intRow, intCol).Value +
Workbooks(2).Worksheets(3).Cells(intRow, intCol).Value
' objSheet1.Cells(intRow, intCol).Value =
objSheet1.Cells(intRow, intCol).Value + objSheet2.Cells(intRow,
intCol).Value
' Stop
Next
Next
End Sub
from the individual file to my master file. I have a macro but it
brings back the values from the specified ranges, does not add
anything. Is ther a way to change this macro to hep add few
cells.....-------here is the macro i have
Public Sub UPDATE_FORECAST_06()
On Error Resume Next
Dim objBook As Excel.Workbook
Dim intLoop As Integer
If (Workbooks.Count > 1) Then
MsgBox "Please close all workbooks except the 4 WAY MATCH -2006
workbook and try again.", vbInformation, "4 WAY MATCH"
Else
With Workbooks(1).Worksheets("FCT REF")
ClearTotals
Do While True
intLoop = intLoop + 1
If (Trim(.Cells(intLoop, 1)) <> "") Then
Set objBook = Workbooks.Open(.Cells(intLoop, 1),
False, , , .Cells(intLoop, 2))
' tester1 = Trim(.Cells(intLoop, 1))
' 'tester2 = Trim(.Cells(intLoop, 2))
' Stop
If (objBook Is Nothing) Then
.Cells(intLoop, 3) = "Failed - " &
Err.Description
Else
ProcessOperatingActual
ProcessOperatingPlan
'ProcessForecastedPLAN
'ProcessProjectCapitalPlan
' Stop
objBook.Saved = True
objBook.Close
.Cells(intLoop, 3) = "Succeeded"
End If
Set objBook = Nothing
Else
Exit Do
End If
Loop
MsgBox "Finished", vbInformation, "Summary"
End With
End If
On Error GoTo 0
End Sub
Private Sub ProcessOperatingActual()
' Set objSheet1 = Workbooks(1).Worksheets(2)
' Set objSheet2 = Workbooks(2).Worksheets(2)
ProcessRange 6, 8, 4, 27
' Where 6 and 8 reperesent rows & 4, 24 represent columns
ProcessRange 12, 16, 4, 27
ProcessRange 20, 23, 4, 27
ProcessRange 27, 31, 4, 27
ProcessRange 37, 39, 4, 27
ProcessRange 43, 44, 4, 27
ProcessRange 48, 61, 4, 27
ProcessRange 67, 75, 4, 27
Set objSheet1 = Nothing
Set objSheet2 = Nothing
End Sub
Private Sub ProcessOperatingPlan()
' Set objSheet1 = Workbooks(1).Worksheets(3)
'Set objSheet2 = Workbooks(2).Worksheets(3)
ProcessRange2 8, 10, 4, 15
ProcessRange2 14, 18, 4, 15
ProcessRange2 22, 25, 4, 15
ProcessRange2 29, 33, 4, 15
ProcessRange2 39, 41, 4, 15
ProcessRange2 45, 46, 4, 15
ProcessRange2 50, 63, 4, 15
ProcessRange2 69, 77, 4, 15
Set objSheet1 = Nothing
Set objSheet2 = Nothing
End Sub
' Private Sub ProcessForecastedPLAN()
'Set objSheet1 = Workbooks(1).Worksheets(3)
'
'Set objSheet2 = Workbooks(2).Worksheets(3)
' ProcessRange 5, 7, 4, 15
' ProcessRange 11, 17, 4, 15
'ProcessRange 21, 24, 4, 15
'ProcessRange 28, 33, 4, 15
'ProcessRange 39, 44, 4, 15
'ProcessRange 48, 49, 4, 15
'ProcessRange 53, 71, 4, 15
'ProcessRange 75, 83, 4, 15
'ProcessRange 89, 101, 4, 15
' Set objSheet2 = Nothing
'End Sub
'Private Sub ProcessProjectCapitalPlan()
' Set objSheet1 = Workbooks(1).Worksheets(5)
'Set objSheet2 = Workbooks(2).Worksheets(5)
'ProcessRange 5, 7, 4, 15
' ProcessRange 11, 17, 4, 15
' ProcessRange 21, 24, 4, 15
'ProcessRange 28, 33, 4, 15
'ProcessRange 39, 44, 4, 15
'ProcessRange 48, 49, 4, 15
'ProcessRange 53, 71, 4, 15
'ProcessRange 75, 83, 4, 15
'ProcessRange 89, 101, 4, 1
'Set objSheet1 = Nothing
' Set objSheet2 = Nothing
'End Sub
Private Sub ProcessRange(ByVal StartRow As Integer, ByVal EndRow As
Integer, ByVal StartColumn As Integer, ByVal EndColumn As Integer)
Dim intRow As Integer
Dim intCol As Integer
For intRow = StartRow To EndRow
For intCol = StartColumn To EndColumn
Workbooks(1).Worksheets(2).Cells(intRow, intCol).Value =
Workbooks(1).Worksheets(2).Cells(intRow, intCol).Value +
Workbooks(2).Worksheets(2).Cells(intRow, intCol).Value
' Stop
' objSheet1.Cells(intRow, intCol).Value =
objSheet1.Cells(intRow, intCol).Value + objSheet2.Cells(intRow,
intCol).Value
Next
Next
End Sub
Private Sub ProcessRange2(ByVal StartRow As Integer, ByVal EndRow As
Integer, ByVal StartColumn As Integer, ByVal EndColumn As Integer)
Dim intRow As Integer
Dim intCol As Integer
For intRow = StartRow To EndRow
For intCol = StartColumn To EndColumn
' Stop
Workbooks(1).Worksheets(3).Cells(intRow, intCol).Value =
Workbooks(1).Worksheets(3).Cells(intRow, intCol).Value +
Workbooks(2).Worksheets(3).Cells(intRow, intCol).Value
' objSheet1.Cells(intRow, intCol).Value =
objSheet1.Cells(intRow, intCol).Value + objSheet2.Cells(intRow,
intCol).Value
' Stop
Next
Next
End Sub