SUM for Google Sheets

Kalusia19943

New Member
Joined
Mar 6, 2023
Messages
3
Office Version
  1. 365
Platform
  1. MacOS
Hello,

I would like to ask how to sum a numbers in one cell which were deleted? I mean, every week I need to update the number in the cell and I wish to get the total of those numbers from last 4 weeks in another cell. How to do this?
For example: I input in cell C10 : 24, one week later I need to delete 24 and change to C10: 30, how I can get a total of those two numbers in C24 (24+30=54) ?
I need to keep somehow the numbers which I deleted to get the total number from the month
 
Last edited by a moderator:

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
here is a macro option

VBA Code:
Sub AddToC10()
    ' Declare variables for user input and current cell value
    Dim userInput As Integer
    Dim currentValue As Integer
    
    ' Get the current value in cell C10
    currentValue = Range("C10").Value
    
    ' Prompt the user to enter a number to add to C10
    userInput = InputBox("Enter a number to add to C10:")
    
    ' Add the user input to the current value of C10
    Range("C10").Value = currentValue + userInput
End Sub

To use this macro, follow these steps:
  1. Open the Excel file where you want to use the macro.
  2. Press Alt + F11 to open the Visual Basic Editor.
  3. In the Visual Basic Editor, select Insert > Module from the menu bar.
  4. Copy and paste the code above into the new module.
  5. Press F5 or select Run > Run Sub/UserForm to run the macro.
  6. Enter a number in the input box that appears and click "OK".
  7. The macro will add the entered number to the current value of cell C10, and store the result back in C10.
 
Upvote 0
here is a macro option

VBA Code:
Sub AddToC10()
    ' Declare variables for user input and current cell value
    Dim userInput As Integer
    Dim currentValue As Integer
   
    ' Get the current value in cell C10
    currentValue = Range("C10").Value
   
    ' Prompt the user to enter a number to add to C10
    userInput = InputBox("Enter a number to add to C10:")
   
    ' Add the user input to the current value of C10
    Range("C10").Value = currentValue + userInput
End Sub

To use this macro, follow these steps:
  1. Open the Excel file where you want to use the macro.
  2. Press Alt + F11 to open the Visual Basic Editor.
  3. In the Visual Basic Editor, select Insert > Module from the menu bar.
  4. Copy and paste the code above into the new module.
  5. Press F5 or select Run > Run Sub/UserForm to run the macro.
  6. Enter a number in the input box that appears and click "OK".
  7. The macro will add the entered number to the current value of cell C10, and store the result back in C10.
Thank you so much.
Is there any other options what I can use in Google sheet?
 
Upvote 0
If you are using Google Sheets, you should make that clear right at the start. Also questions relating to Sheets should be posted in the General Discussion & Other Applications section of the board.

I have done that for you this time.
 
Upvote 0
Thank you so much.
Is there any other options what I can use in Google sheet?
below is direct from ChatGPT, see if that help.

Yes, the Excel macro can be converted to a Google Sheets script to perform the same functionality. Here's an example of how to do it:
  1. Open the Google Sheets file where you want to add the macro.
  2. Select Tools > Script editor from the menu.
  3. In the Script editor, copy and paste the following code:
VBA Code:
function AddToC10() {
  var userInput = parseInt(prompt("Enter a number to add to C10:"));
  var sheet = SpreadsheetApp.getActive().getSheetByName("Sheet1");
  var currentValue = sheet.getRange("C10").getValue();
  sheet.getRange("C10").setValue(currentValue + userInput);
}

  1. Replace "Sheet1" in the third line with the name of the sheet where the cell C10 is located.
  2. Save the script and close the Script editor.
  3. Back in the Google Sheets file, select the cell where you want to add the button to run the macro.
  4. Select Insert > Drawing from the menu.
  5. In the Drawing window, select the shape you want to use as the button and draw it in the desired size.
  6. Click Save and Close.
  7. Click the button you just created and select Assign script from the menu.
  8. Type "AddToC10" (without quotes) in the input box and click OK.
  9. Close the Drawing window.
  10. Now, whenever you click the button, the macro will prompt you for a number to add to cell C10 and store the result in cell C10.
 
Upvote 0
below is direct from ChatGPT, see if that help.

Yes, the Excel macro can be converted to a Google Sheets script to perform the same functionality. Here's an example of how to do it:
  1. Open the Google Sheets file where you want to add the macro.
  2. Select Tools > Script editor from the menu.
  3. In the Script editor, copy and paste the following code:
VBA Code:
function AddToC10() {
  var userInput = parseInt(prompt("Enter a number to add to C10:"));
  var sheet = SpreadsheetApp.getActive().getSheetByName("Sheet1");
  var currentValue = sheet.getRange("C10").getValue();
  sheet.getRange("C10").setValue(currentValue + userInput);
}

  1. Replace "Sheet1" in the third line with the name of the sheet where the cell C10 is located.
  2. Save the script and close the Script editor.
  3. Back in the Google Sheets file, select the cell where you want to add the button to run the macro.
  4. Select Insert > Drawing from the menu.
  5. In the Drawing window, select the shape you want to use as the button and draw it in the desired size.
  6. Click Save and Close.
  7. Click the button you just created and select Assign script from the menu.
  8. Type "AddToC10" (without quotes) in the input box and click OK.
  9. Close the Drawing window.
  10. Now, whenever you click the button, the macro will prompt you for a number to add to cell C10 and store the result in cell C10.
Thank you for help, any idea where else can I find script editor as I don't have it in tools?
 

Attachments

  • Screen Shot 2023-03-08 at 10.08.02 AM.png
    Screen Shot 2023-03-08 at 10.08.02 AM.png
    50.8 KB · Views: 6
Upvote 0
Thank you for help, any idea where else can I find script editor as I don't have it in tools?
I don't use google sheet, unfortunately.
just google it and got this

Why can't i find script editor on Google Sheets?


Click Extensions > Apps Script to open the script editor, then copy the script text from the original spreadsheet and paste it into the script editor of another spreadsheet.
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,219
Members
452,619
Latest member
Shiv1198

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