SumProduct result as Text Box value in VBA

FBZM_27

New Member
Joined
Aug 10, 2014
Messages
4
Hi everyone,
I'm new to this forum and this is my first post.
I have a worksheet where I use this function =SUMPRODUCT(--(MONTH('2014'!C1:XFD1)=MONTH(C1)),--(YEAR('2014'!C1:XFD1)=YEAR(C1))+0,'2014'!C25:XFD25) to calculate the total sales volume in a given month and year.
I want the result of this function to show in a text box of a user form I'm creating but I don't know how.
I tried a lot of solutions I read here on Mr.Excel but I don't really know what I'm doing most of the time so I didn't make any progress.
Could you help me?
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
I kept trying yesterday and this works partially:
Code:
Dim P As Integer
P = Evaluate("=SUMPRODUCT(--(Month(C1:XFD1)=Month(C1)),--(Year(C1:XFD1)=Year(C1))+0,C25:XFD25)")
txtParziale = P

I said it works partially because the result I get in the text box is not the sum of all values in the cells in range
C25:XFD25, if the corresponding cell in range C1:XFD1 meets my month and year criteria, but only the value in the first cell of the range, which is C25.
The criteria seem to be working fine so I believe I'm not handling ranges properly.
Could someone help me?
 
Last edited:
Upvote 0
I kept trying today as well and now I'm pretty sure the problem isn't how I'm handling ranges but the format of dates in C1:XFD1.
I believe they're seen as text, not as numbers, but I'll try to figure out more tomorrow.
 
Upvote 0
As you may guess, oh imaginary readers, I kept trying and finallly got it right.
The problem was that dates in range C1:XFD1 weren't set as dates (you can see if a date is a date by checking if you get the it's serial number when formatting the cell as number).
To solve it I simply had to convert any input to date before putting it in a cell:
Range("C1").Value = CDate(txtData.Value)
instead of
Range("C1").Value = txtData.Value
I guess excel helps those who help themselves.
 
Upvote 0

Forum statistics

Threads
1,223,243
Messages
6,170,971
Members
452,371
Latest member
Frana

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