powerpivot VBA help

MartinL

Well-known Member
Joined
Oct 16, 2008
Messages
1,141
Office Version
  1. 365
Platform
  1. Windows
Hi everyone

[Sorry originally posted this to the wrong group, duh and some kind person :nya: put it in an even wronger group]

I have a sheet that uses a UDF to get the weight from a product string

[Code:]Function Wgt(rCell As Range) As Double
'***************************************************************
'*Extract a number from a cell containing text and numbers.
'*i.e. JSBBC120X006 TrayCount = 6
'***************************************************************

Dim iCount As Integer, i As Integer, iLoop As Integer
Dim sText As String
Dim lNum As String
Dim vVal
Dim Flag As Boolean


'get the Alphanumeric value of the cell
sText = rCell

'determine the number of characters in the cell
iLoop = Len(sText)

'Set up the counter to loop backwards through the length of the cell
For iCount = 1 To iLoop

'Put the value of the character determined by the counter into vVal
vVal = Mid(sText, iCount, 1)

'If vVal = "X" Then Flag = True

'If Flag = True Then _
'If vVal is a number add 1 to i and put the number into lNum
If IsNumeric(vVal) Then
i = i + 1
lNum = lNum & Mid(sText, iCount, 1)

End If
'End If

'If you have collected some numbers but now there is some text (ie "x") stop.
If i > 0 And IsNumeric(vVal) = False Then GoTo Finish
Next iCount


Finish:
'put the value of lNum into the cell
If lNum = "" Then lNum = 0
If lNum < 10 Then lNum = 0
Wgt = CDbl(lNum)
End Function
[/Code]


However I am now using powerpivot and I need to get this value into a new column with powerpivot, unless somone can suggest another way.

Any ideas

Martin
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Please post a few examples of the original strings along with the result (weight) that you would want returned.
 
Upvote 0
Hi Thanks for the reply

I'm off work at the moment (moving house).

I am back in work on Tuesday and will post a few examples with expected results then.

Martin
 
Upvote 0
Sorry this has taken so long, Moving house caused major disruption to my internet access as well as my head :rofl:

Here are some example of the data and expected results, zero is returned where no weight is available in the description.
As previously stated I have used VBA in the past to create these results but how can I populate a column in Powerpivot withthe same results?

*BC
DescriptionWeight
Goose Fat Roast Potatoes +30%
'M'mash Potato 450G
Goose Fat Roast Potatoes 450G
'M'cajun Wedges & Chive Dip
'M'jacket Pot & Garlic Butter
'M'crispy Potato Slices 400G
'M'maris Piper Potato Mash
'M'ivy Vintage Cheddar Mash
'M'potato Leek & Gruyere Bake
'M'garlic Saute Potatoes 350G
'M'chunky Chips 400G
'M'parmentier Potatoes 400G
'M'parmesan Potatoes 400G
Potato Wedges 600G
Baby Pot/Herb Butter
Co-Op Eat In Chunky Chips 360G
Co-Op Garlic Drilled Jackets 345G
Co-Op Crispy Potato Slices 300G
Mash Direct Potato Cakes 250G
Co-Op Eat In Paramentier Potatoes 360G
Co-Op. Ti Mash Pot+Crm&Butter 450 G
Co-Op Carrot And Swede Mash Potato 400G
Co-Op. Maris Piper Mash Pots 400 G
Mash Direct Champ
Md Mash Potato
Co-Op. Ti Potato Dauphinoise 400 G
Co-Op. New Pots/Butter/Hrb 360 G
Tesco Maris Piper Mash425g
T. New Potatoes With Herb And Butter 360G (C)

<colgroup><col style="width: 30px; font-weight: bold;"><col style="width: 433px;"><col style="width: 64px;"></colgroup><tbody>
[TD="bgcolor: #CACACA, align: center"]2[/TD]

[TD="bgcolor: #CACACA, align: center"]3[/TD]

[TD="align: right"]0[/TD]

[TD="bgcolor: #CACACA, align: center"]4[/TD]

[TD="align: right"]450[/TD]

[TD="bgcolor: #CACACA, align: center"]5[/TD]

[TD="align: right"]450[/TD]

[TD="bgcolor: #CACACA, align: center"]6[/TD]

[TD="align: right"]0[/TD]

[TD="bgcolor: #CACACA, align: center"]7[/TD]

[TD="align: right"]0[/TD]

[TD="bgcolor: #CACACA, align: center"]8[/TD]

[TD="align: right"]400[/TD]

[TD="bgcolor: #CACACA, align: center"]9[/TD]

[TD="align: right"]0[/TD]

[TD="bgcolor: #CACACA, align: center"]10[/TD]

[TD="align: right"]0[/TD]

[TD="bgcolor: #CACACA, align: center"]11[/TD]

[TD="align: right"]0[/TD]

[TD="bgcolor: #CACACA, align: center"]12[/TD]

[TD="align: right"]350[/TD]

[TD="bgcolor: #CACACA, align: center"]13[/TD]

[TD="align: right"]400[/TD]

[TD="bgcolor: #CACACA, align: center"]14[/TD]

[TD="align: right"]400[/TD]

[TD="bgcolor: #CACACA, align: center"]15[/TD]

[TD="align: right"]400[/TD]

[TD="bgcolor: #CACACA, align: center"]16[/TD]

[TD="align: right"]600[/TD]

[TD="bgcolor: #CACACA, align: center"]17[/TD]

[TD="align: right"]0[/TD]

[TD="bgcolor: #CACACA, align: center"]18[/TD]

[TD="align: right"]360[/TD]

[TD="bgcolor: #CACACA, align: center"]19[/TD]

[TD="align: right"]345[/TD]

[TD="bgcolor: #CACACA, align: center"]20[/TD]

[TD="align: right"]300[/TD]

[TD="bgcolor: #CACACA, align: center"]21[/TD]

[TD="align: right"]250[/TD]

[TD="bgcolor: #CACACA, align: center"]22[/TD]

[TD="align: right"]360[/TD]

[TD="bgcolor: #CACACA, align: center"]23[/TD]

[TD="align: right"]450[/TD]

[TD="bgcolor: #CACACA, align: center"]24[/TD]

[TD="align: right"]400[/TD]

[TD="bgcolor: #CACACA, align: center"]25[/TD]

[TD="align: right"]400[/TD]

[TD="bgcolor: #CACACA, align: center"]26[/TD]

[TD="align: right"]0[/TD]

[TD="bgcolor: #CACACA, align: center"]27[/TD]

[TD="align: right"]0[/TD]

[TD="bgcolor: #CACACA, align: center"]28[/TD]

[TD="align: right"]400[/TD]

[TD="bgcolor: #CACACA, align: center"]29[/TD]

[TD="align: right"]360[/TD]

[TD="bgcolor: #CACACA, align: center"]30[/TD]

[TD="align: right"]425[/TD]

[TD="bgcolor: #CACACA, align: center"]31[/TD]

[TD="align: right"]360[/TD]

</tbody>


Excel tables to the web >> http://www.excel-jeanie-html.de/index.php?f=1" target="_blank"> Excel Jeanie HTML 4
 
Upvote 0

Forum statistics

Threads
1,223,277
Messages
6,171,148
Members
452,382
Latest member
RonChand

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