VBA to populate a textbox with a range sum

EssKayKay

Active Member
Joined
Jan 5, 2003
Messages
407
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

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
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,223,886
Messages
6,175,194
Members
452,616
Latest member
intern444

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