VBA to populate a textbox with a range sum

EssKayKay

Active Member
Joined
Jan 5, 2003
Messages
358
Office Version
  1. 2007
Platform
  1. Windows
Hello,
I’m trying to streamline my code and cleanup my worksheet a bit if possible.

I have a textbox (txtYTD) in a UserForm (frmPITI) that displays the sum of a range. I can get this to work if I sum the range; place the value in a cell; then populate the textbox with the value in the cell.

Here’s a snipit of the code that works:
VBA Code:
Range("P25").Formula = "=Sum(U33:U2033)"
txtYTD = Range("P25")

However, I like to do this directly from VBA without having to populate a cell (i.e., P25). That is, something like txtYTD. Formula = "=Sum(U33:U2033)".
Any suggestions?

Thanks for viewing,
Steve K.
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Give this a try:

VBA Code:
txtYTD = Application.WorksheetFunction.Sum(Range("U33:U2033"))
 
Upvote 0
Solution
try this syntax with your own references
userform.TextBox2 =application.WorksheetFunction.sum(sheets("D").range("E4:F4"))
 
Upvote 0
Thank you guys. Both of these solutions worked great. Much appreciated.
SKK
 
Upvote 1

Forum statistics

Threads
1,221,310
Messages
6,159,176
Members
451,543
Latest member
cesymcox

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