Can you help me in debugging the following code with sumif?

saftawy1

Board Regular
Joined
Oct 12, 2021
Messages
65
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
I have a column B that contains the date, and a column "i" that contains incoming values, a column" j "that contains spent values, and a textbox1 contains a date and a Textbox 2 is required to show the result of collecting column cells, "i". that are smaller than the date in textbox 1, as well as collecting "j"column cells that are smaller than the date of textbox 1, then subtracting the first result from the second and showing it in textbox 2
VBA Code:
Dim m As Double
Set ws = ThisWorkbook.Sheets("kh")
m = prosafty.TextBox1.Value
      prosafty.TextBox2.Value = WorksheetFunction.SumIf(ws.Range("b4:b100000"), "<m", ws.Range("i4:i100000")) _
      - WorksheetFunction.SumIf(ws.Range("b4:b100000"), "<m", ws.Range("j4:j10000"))
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Hi saftawy1,

I think that the criteria argument should be "<" & m rather than "<m".

I could be wrong. I tested only on a worksheet with the formula and the "m" being a cell reference.

Hope that helps,

Doug
 
Upvote 0
Hi saftawy1,

I think that the criteria argument should be "<" & m rather than "<m".

I could be wrong. I tested only on a worksheet with the formula and the "m" being a cell reference.

Hope that helps,

Doug
i try but not work with textbox
 
Upvote 0
i try but not work with textbox
i solved it with your help and and small modifay in the code by used cdate ty
VBA Code:
Dim m As Double
Set ws = ThisWorkbook.Sheets("kh")
m = cdate(prosafty.TextBox1.Value)
      prosafty.TextBox2.Value = WorksheetFunction.SumIf(ws.Range("b4:b100000"), "<" & M, ws.Range("i4:i100000")) _
      - WorksheetFunction.SumIf(ws.Range("b4:b100000"), "<" & M, ws.Range("j4:j10000"))
 
Upvote 0
Solution
Can you get the SUMIF formula to work on the worksheet? Possibly use the "LinkedCell" property of the textbox and reference those in your formula/vba. I was thinking "Type mismatch" with the textbox value but you have m declared as a Double. I think textboxes are Strings usually...
 
Upvote 0
I didn't know you were working with dates. "m" declared as double, with CDATE...they can be tricky I guess. Glad you got it working.
 
Upvote 0

Forum statistics

Threads
1,224,728
Messages
6,180,600
Members
452,989
Latest member
Ol Reliable

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