Input box and sum

jmoney30

New Member
Joined
Dec 19, 2020
Messages
31
Office Version
  1. 2016
How do I use an input to replace the sheet name that I’m doing calculations on. Every month the sheet name changes and I want to use an input box that changes this formula every month.

Month = InputBox(“Insert Month”)

This is the formula.
>Worksheets("Sheet1").Range("a1") = "=SUM(Sheet2!P:P)"

Trying to get this to work but formula keeps using the word month and not the month value.

>Worksheets("Sheet1").Range("a1") = "=SUM(Month!P:P)"
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
@jmoney30

Two things I see. Month is a function so cannot be used as a variable. In the formula you will need to concatenate the variable string within the other portions of the formula.
Try
VBA Code:
MyMonth = InputBox("Insert Month")
Worksheets("Sheet3").Range("a1") = "=SUM(" & MyMonth & "!P:P)"

Hope that helps.
 
Upvote 0
Hi
@jmoney30

Two things I see. Month is a function so cannot be used as a variable. In the formula you will need to concatenate the variable string within the other portions of the formula.
Try
VBA Code:
MyMonth = InputBox("Insert Month")
Worksheets("Sheet3").Range("a1") = "=SUM(" & MyMonth & "!P:P)"

Hope that helps.
Hi it works thanks
 
Upvote 0

Forum statistics

Threads
1,213,543
Messages
6,114,243
Members
448,555
Latest member
RobertJones1986

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