Count Numbers Next To Variables

rvill189

New Member
Joined
Mar 12, 2022
Messages
16
Office Version
  1. 2016
Platform
  1. Windows
Hello,

I am trying to create a formula in a daily inventory that calculates the number of pallets (indicated as P) in a column. As you can see below screenshot examples, "<value>P" is not always in the same position in the cell, and cells contain values that I do not need to account for (boxes, rolls, the "+" and "=" signs, etc.):

1647125955303.png
1647126646172.png
1647126977212.png


I want the formula to evaluate column E:E and calculate the number next to P only and whenever it exists next to P.

As an example between the three screenshots, the total the formula should return is 159.
 

Attachments

  • 1647126620577.png
    1647126620577.png
    4.8 KB · Views: 6
I return the below error after entering the VBA code and formula:
Two things.

1. I'm guessing that you pasted the vba code in the wrong place. Check that it is in a standard module, not a worksheet module.

1647134325113.png


2. The formula in the worksheet is incorrect - you have extra text in there. It should be
Excel Formula:
=Pallets(ProductPriceList[PHYSICAL Quantity])
 
Upvote 0

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Hi,

Here's one way with a Helper column in B (or anywhere on your sheet) that you can hide, all the "heavy lifting" is done in the helper:

Book3.xlsx
ABCD
1PHYSICAL QuantityPallet total:183
21P1P
31P1P
411P11P
51P1P
65BXS+1P1P
740P40P
88P8P
918P18P
109P9P
1114P14P
127P7P
137P7P
145P5P
152P2P
167P7P
178P8P
1810P10P
195P+35BXS5P
2013P13P
214P4P
222P+3BXS2P
235BXS0P
241BX0P
256BXS0P
269P=32ROLLS9P
Sheet1044
Cell Formulas
RangeFormula
D1D1=SUMPRODUCT(--(LEFT(B2:B26,LEN(B2:B26)-1)))
B2:B26B2=IF(ISERR(SEARCH("P",A2)),"0P",TRIM(IF(RIGHT(A2)="P",RIGHT(SUBSTITUTE(SUBSTITUTE(A2,"=",REPT(" ",99)),"+",REPT(" ",99)),99),LEFT(SUBSTITUTE(SUBSTITUTE(A2,"=",REPT(" ",99)),"+",REPT(" ",99)),99))))

Thank you!

Your response worked. The actual spreadsheet is well over 500 rows, and I leave it as a table should warehouse auditors need to add additional entries.

The formula in D1 does not add the P values of additional row entries. How can I make it so that D1 will constantly update when a row is removed or added?
 
Upvote 0
To have the helper column you could add a new column to your table like this.
Hide the new column if you want.

rvill189.xlsm
BCDEF
1PHYSICAL QuantityPalletsPallet total:159
28P8
31P1
423BXS=2P2
52P2
61P+33BXS1
744P44
840P40
92P2
1011P11
1110P10
125BXS0
139P=32ROLLS9
1410P10
151BX0
166BXS0
172P+17BXS2
185P5
1910P10
202P+17BXS2
21
22
Sheet1
Cell Formulas
RangeFormula
F1F1=SUM(ProductPriceList[Pallets])
C2:C20C2=AGGREGATE(14,6,RIGHT(LEFT([@[PHYSICAL Quantity]]&"0P",FIND("P",[@[PHYSICAL Quantity]]&"0P")-1),{1,2,3,4,5})+0,1)
 
Upvote 0
Thank you!

Your response worked. The actual spreadsheet is well over 500 rows, and I leave it as a table should warehouse auditors need to add additional entries.

The formula in D1 does not add the P values of additional row entries. How can I make it so that D1 will constantly update when a row is removed or added?

You can do 1 of 2 things, since you're likely to "Hide" the helper column, you can Pre-populate the helper with the B formula, and use the D formula as-is, or you can use the updated formula in D1, array-entered.

Book3.xlsx
ABCD
1PHYSICAL QuantityPallet total:183
21P1P183
31P1P
411P11P
51P1P
65BXS+1P1P
740P40P
88P8P
918P18P
109P9P
1114P14P
127P7P
137P7P
145P5P
152P2P
167P7P
178P8P
1810P10P
195P+35BXS5P
2013P13P
214P4P
222P+3BXS2P
235BXS0P
241BX0P
256BXS0P
269P=32ROLLS9P
270P
280P
290P
300P
Sheet1044
Cell Formulas
RangeFormula
D1D1=SUMPRODUCT(--IFERROR(LEFT(B2:B100,LEN(B2:B100)-1),0))
D2D2=SUMPRODUCT(--LEFT(B2:B100,LEN(B2:B100)-1))
B2:B30B2=IF(ISERR(SEARCH("P",A2)),"0P",TRIM(IF(RIGHT(A2)="P",RIGHT(SUBSTITUTE(SUBSTITUTE(A2,"=",REPT(" ",99)),"+",REPT(" ",99)),99),LEFT(SUBSTITUTE(SUBSTITUTE(A2,"=",REPT(" ",99)),"+",REPT(" ",99)),99))))
Press CTRL+SHIFT+ENTER to enter array formulas.
 
Upvote 0
Wow.. this is perfect. I can see its appli
To have the helper column you could add a new column to your table like this.
Hide the new column if you want.

rvill189.xlsm
BCDEF
1PHYSICAL QuantityPalletsPallet total:159
28P8
31P1
423BXS=2P2
52P2
61P+33BXS1
744P44
840P40
92P2
1011P11
1110P10
125BXS0
139P=32ROLLS9
1410P10
151BX0
166BXS0
172P+17BXS2
185P5
1910P10
202P+17BXS2
21
22
Sheet1
Cell Formulas
RangeFormula
F1F1=SUM(ProductPriceList[Pallets])
C2:C20C2=AGGREGATE(14,6,RIGHT(LEFT([@[PHYSICAL Quantity]]&"0P",FIND("P",[@[PHYSICAL Quantity]]&"0P")-1),{1,2,3,4,5})+0,1)
Wow! This is amazing.

I will likely keep the "Pallet Total" cells aside from the table; however, is it at all possible to enter a formula in the header of a table? I have tried in previous circumstances and the formula disappears altogether and returns a 0.

Otherwise, this is what I was looking for.
 
Last edited by a moderator:
Upvote 0
I will likely keep the "Pallet Total" cells aside from the table;
Why? Having it in the table (& hidden if you want) is the easy way to get the automatic expansion/contraction if the table changes size.

is it at all possible to enter a formula in the header of a table?
No, I don't believe so.

BTW, did you get the udf version working?
 
Upvote 0
Why? Having it in the table (& hidden if you want) is the easy way to get the automatic expansion/contraction if the table changes size.


No, I don't believe so.

BTW, did you get the udf version working?
I agree, hidden should do it.

I did not get the udf version working. The spreadsheet is updated on a .csv spreadsheet via Tablet and I do not think this would be able to convert/open correct on their Tablet.

I will test this out on the actual spreadsheet and keep you posted!

Thanks so much.
 
Upvote 0
I do not think this would be able to convert/open correct on their Tablet.
OK, that could well be the case.

BTW, it would still be a good idea to update your version details (see post #7) since different versions have different functions and features available to them.
 
Upvote 0
OK, that could well be the case.

BTW, it would still be a good idea to update your version details (see post #7) since different versions have different functions and features available to them.
Thanks so much,

I missed that note. Updated just now.
 
Upvote 0

Forum statistics

Threads
1,216,108
Messages
6,128,872
Members
449,475
Latest member
Parik11

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