Help with "" and & again...

JARichard74

Board Regular
Joined
Dec 16, 2019
Messages
114
Office Version
  1. 365
Platform
  1. Windows
Get error 1004 Application defined error
VBA Code:
.Range(.Cells(startCell, 6), .Cells(startCell, 6)).Formula = "=(COUNTIFS(B" & startRow & ":B" & endRow & ", ""<""& " & Hrngel & ",B" & startRow & ":B" & endRow & ", "">""& " & Hrngeh & ", ""<""& B" & startCell & ")+1)"
Where
Hrngel = WorksheetFunction.Average(Range("B" & startRow & ":B" & endRow)) - WorksheetFunction.StDev(Range("B" & startRow & ":B" & endRow))
Hrngeh = WorksheetFunction.Average(Range("B" & startRow & ":B" & endRow)) + WorksheetFunction.StDev(Range("B" & startRow & ":B" & endRow))
Both Dim As Double
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
You're either missing a range or have too many criteria for the formula.
I would need to see an example of the expected worksheet formula in order to correct it.
 
Upvote 0
You're either missing a range or have too many criteria for the formula.
I would need to see an example of the expected worksheet formula in order to correct it.
=COUNTIFS($A$6:$A$8,"<"&Hrngeh,$A$6:$A$8,">"&Hrngel,$A$6:$A$8,"<"&A6)
Hrngeh = E2 which = AVERAGE(A6:A8)+STDEV(A6:A8)
Hrngel = D2 which = AVERAGE(A6:A8)-STDEV(A6:A8)
 
Upvote 0
The third $A$6:$A$8 was missing, this should work
VBA Code:
.Range(.Cells(startCell, 6), .Cells(startCell, 6)).Formula = "=(COUNTIFS(B" & startRow & ":B" & endRow & ", ""<""& " & Hrngel & ",B" & startRow & ":B" & endRow & ", "">""& " & Hrngeh & ",B" & startRow & ":B" & endRow & ", ""<""& B" & startCell & ")+1)"
 
Upvote 0
Solution
The third $A$6:$A$8 was missing, this should work
VBA Code:
.Range(.Cells(startCell, 6), .Cells(startCell, 6)).Formula = "=(COUNTIFS(B" & startRow & ":B" & endRow & ", ""<""& " & Hrngel & ",B" & startRow & ":B" & endRow & ", "">""& " & Hrngeh & ",B" & startRow & ":B" & endRow & ", ""<""& B" & startCell & ")+1)"
Thank you!
 
Upvote 0

Forum statistics

Threads
1,216,084
Messages
6,128,722
Members
449,465
Latest member
TAKLAM

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