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

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Welcome to Mr. Excel,

It would help if you show your data and expected results using XL2BB so that it's understood (at least for me) what the solutions are.
 
Upvote 0
Welcome to Mr. Excel,

It would help if you show your data and expected results using XL2BB so that it's understood (at least for me) what the solutions are.
Thank you,

Pallet Inventory.xlsx
ABCD
9LABEL Quantity PHYSICAL QuantityRECEIVE DATEDAYS IN WAREHOUSE
1011P 
1111P 
121111P 
1311P 
1465BXS+1P 
154040P 
1688P 
171818P 
18NO QTY9P 
191414P 
2077P 
2177P 
2255P 
2322P 
2477P 
2588P 
261010P 
27405P+35BXS 
281313P 
2944P 
3052P+3BXS 
Product Price List
Cell Formulas
RangeFormula
D10:D30D10=IF(ISBLANK([@[RECEIVE DATE]]),"",ABS(DAYS([@[RECEIVE DATE]],TODAY())))
Cells with Conditional Formatting
CellConditionCell FormatStop If True
C106:D1048576,C5,C8:C9Cell Valuecontains "completo"textNO
Cells with Data Validation
CellAllowCriteria
A9:B9Any value
C9Any value
D9:D30Any value
 
Upvote 0
Reduced to what I am only looking at:

Pallet Inventory.xlsx
ABCD
9PHYSICAL QuantityPallet total:
101P
111P
1211P
131P
145BXS+1P
1540P
168P
1718P
189P
1914P
207P
217P
225P
232P
247P
258P
2610P
275P+35BXS
2813P
294P
302P+3BXS
Product Price List
Cells with Data Validation
CellAllowCriteria
A9Any value
 
Upvote 0
What results do you want that are associated with the rows?
Would be helpful if you changed your profile to indicate what version of Excel you run.
 
Last edited:
Upvote 0
What results do you want that are associated with the rows?
I need a formula that evaluates the column and calculates the values attached to P only. P represents "pallets on inventory". In the second table I attached, the formula should evaluate column A (or Physical Quantity) and return 174. The formula would ignore everything else that does not have a value attached to P.
 
Upvote 0
Welcome to the MrExcel board!

I suggest that you update your Account details (or click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)

I would employ a user-defined function for this. To implement ..
1. Right click the sheet name tab and choose "View Code".
2. In the Visual Basic window use the menu to Insert|Module
3. Copy and Paste the code below (you can use the icon at the top right of the code pane below) into the main right hand pane that opens at step 2.
4. Close the Visual Basic window.
5. Enter the formula as shown in the screen shot below, adjusting for whatever your actual table name is.
6. Your workbook will need to be saved as a macro-enabled workbook (*.xlsm)

VBA Code:
Function Pallets(r As Range) As Long
  With CreateObject("VBScript.RegExp")
    .Global = True
    .Pattern = "(.+?)(\d+P)"
    Pallets = Evaluate(Replace(.Replace(" " & Join(Application.Transpose(r)) & " 0P", "+$2"), "P", ""))
  End With
End Function

rvill189.xlsm
ABCDEF
1LABEL QuantityPHYSICAL QuantityPallet total:159
28P
31P
423BXS=2P
52P
61P+33BXS
744P
840P
92P
1011P
1110P
125BXS
139P=32ROLLS
1410P
151BX
166BXS
172P+17BXS
185P
1910P
202P+17BXS
21
22
Sheet1
Cell Formulas
RangeFormula
F1F1=Pallets(Table2[PHYSICAL Quantity])
 
Upvote 0
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))))
 
Upvote 0
Welcome to the MrExcel board!

I suggest that you update your Account details (or click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)

I would employ a user-defined function for this. To implement ..
1. Right click the sheet name tab and choose "View Code".
2. In the Visual Basic window use the menu to Insert|Module
3. Copy and Paste the code below (you can use the icon at the top right of the code pane below) into the main right hand pane that opens at step 2.
4. Close the Visual Basic window.
5. Enter the formula as shown in the screen shot below, adjusting for whatever your actual table name is.
6. Your workbook will need to be saved as a macro-enabled workbook (*.xlsm)

VBA Code:
Function Pallets(r As Range) As Long
  With CreateObject("VBScript.RegExp")
    .Global = True
    .Pattern = "(.+?)(\d+P)"
    Pallets = Evaluate(Replace(.Replace(" " & Join(Application.Transpose(r)) & " 0P", "+$2"), "P", ""))
  End With
End Function

rvill189.xlsm
ABCDEF
1LABEL QuantityPHYSICAL QuantityPallet total:159
28P
31P
423BXS=2P
52P
61P+33BXS
744P
840P
92P
1011P
1110P
125BXS
139P=32ROLLS
1410P
151BX
166BXS
172P+17BXS
185P
1910P
202P+17BXS
21
22
Sheet1
Cell Formulas
RangeFormula
F1F1=Pallets(Table2[PHYSICAL Quantity])
Thank you for your response,

I return the below error after entering the VBA code and formula:
1647133557362.png
 
Upvote 0
You want:

=pallets(ProductPriceList[PHYSICAL Quantity])
 
Upvote 0

Forum statistics

Threads
1,215,025
Messages
6,122,732
Members
449,093
Latest member
Mnur

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