GuyM
September 6th, 2001, 05:13 AM
HI,
I'am trying to add data from 2 seperate spreadsheets together with VB instead of having to do this to manually to 245 fields.
I went to the MS support site (Boo-Hiss) and they suggested this code...
Sub TotalData()
Dim File1 as Object, File2 as Object, CurCell as Object
' Where the first column of data is located in Book1 on Sheet1
' in range A1:A10.
set File1 = Workbooks("Book1").Sheets("Sheet1").Range("A1:A10")
' We are now dealing with the second column of data.
set File2 = Workbooks("Book2").Sheets("Sheet1").Range("A1:A10")
for Each CurCell In Range("A1:A10")
' to add instead of subtract, change the minus sign
' to a plus sign.
CurCell.Value = File1.Cells(CurCell.Row, 1).Value - _
File2.Cells(CurCell.Row, 1).Value
next
End Sub
...which I adapted to...
Sub TotalData()
Dim File1 as Object, File2 as Object, CurCell as Object
' Where the first column of data is located in Book1 on Sheet1
' in range A1:A10.
set File1 = Workbooks("SCMS1").Sheets("Sheet1").Range("B3:B38")
' We are now dealing with the second column of data.
set File2 = Workbooks("SCMS2").Sheets("Sheet1").Range("B3:B38")
for Each CurCell In Range("B3:B38")
' to add instead of subtract, change the minus sign
' to a plus sign.
CurCell.Value = File1.Cells(CurCell.Row, 1).Value + _
File2.Cells(CurCell.Row, 1).Value
next
End Sub
...for my purposes, but sadly it is not adding the column in workbook two to the column in workbook one together. New figures are created in the designated fields but data has neither been added or subtracted correctly, I have no idea where the calulations generated arise from.
Can anyone be of any assistance?
Kind Regards
GuyM
I'am trying to add data from 2 seperate spreadsheets together with VB instead of having to do this to manually to 245 fields.
I went to the MS support site (Boo-Hiss) and they suggested this code...
Sub TotalData()
Dim File1 as Object, File2 as Object, CurCell as Object
' Where the first column of data is located in Book1 on Sheet1
' in range A1:A10.
set File1 = Workbooks("Book1").Sheets("Sheet1").Range("A1:A10")
' We are now dealing with the second column of data.
set File2 = Workbooks("Book2").Sheets("Sheet1").Range("A1:A10")
for Each CurCell In Range("A1:A10")
' to add instead of subtract, change the minus sign
' to a plus sign.
CurCell.Value = File1.Cells(CurCell.Row, 1).Value - _
File2.Cells(CurCell.Row, 1).Value
next
End Sub
...which I adapted to...
Sub TotalData()
Dim File1 as Object, File2 as Object, CurCell as Object
' Where the first column of data is located in Book1 on Sheet1
' in range A1:A10.
set File1 = Workbooks("SCMS1").Sheets("Sheet1").Range("B3:B38")
' We are now dealing with the second column of data.
set File2 = Workbooks("SCMS2").Sheets("Sheet1").Range("B3:B38")
for Each CurCell In Range("B3:B38")
' to add instead of subtract, change the minus sign
' to a plus sign.
CurCell.Value = File1.Cells(CurCell.Row, 1).Value + _
File2.Cells(CurCell.Row, 1).Value
next
End Sub
...for my purposes, but sadly it is not adding the column in workbook two to the column in workbook one together. New figures are created in the designated fields but data has neither been added or subtracted correctly, I have no idea where the calulations generated arise from.
Can anyone be of any assistance?
Kind Regards
GuyM