macro that changes cell reference

Chenboy2

New Member
Joined
Sep 25, 2005
Messages
34
Office Version
  1. 365
Platform
  1. Windows
Using two sheets, one sheet to reference the cells and the other to output the data, I'm trying to see if I can sum a different set of cells each time I run the macro and only adding up the cells with the newly entered data. In addition, previous data will not be summed again. For example, if cells B1:C3 has been summed, the next time I want cells B4:C7 summed, granted that there are numbers in that range of cells. The macro would also need to be able to determine where to start based on the new date in a different cell.

For example, if on Sheet 1 column A was the date column, columns B and C were the two columns with the data, the macro would first reference and copy or reference the date in column A from Sheet 1 into Sheet 2 into cell A1 and then sum columns B and C into cell A2. The next time the same macro is ran, the next date is copied and the data for the corresponding date is copied onto cell A2 and B2, likewise.

Is this even possible to do? Does Excel macros do this?

I hope this makes sense without any screen prints. Please let me know if clarification is needed.

Thanks.
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
If I understood you correctly this macro may help you (main data in sheet 1 and results in sheet2)

Code:
Sub test()
Dim r As Range, x As Double
With Worksheets("sheet1")
Set r = .Cells(Rows.Count, "A").End(xlUp)
x = r.Offset(0, 1) + r.Offset(0, 2)
With Worksheets("sheet2")
.Range("A1") = r
.Range("A1").NumberFormat = "[$-409]d-mmm-yy;@"
.Range("A2") = x
End With
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,285
Members
452,902
Latest member
Knuddeluff

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top