+ Reply to Thread
Results 1 to 2 of 2

Extract substring if condition is met

Hybrid View

  1. #1
    Registered User
    Join Date
    08-30-2016
    Location
    Indiana
    MS-Off Ver
    Starter
    Posts
    1

    Extract substring if condition is met

    I am having a problem getting my vending machine sheet to work properly & would appreciate any help.

    The sales sheet is usually filled with a copy/paste from an online report (html). Other columns have irrelevant data but I want to extract from the H column. The items are listed in format "00xx(x.xx)". This shows a sale of item 00xx for cost (x.xx). Sometimes there are up to 3 items sold at once possibly with different item numbers & prices ex. "00xx(x.xx), 00xx(x.xx), 00yy(y.yy)"

    Costs & product placement vary on different machines but only 1 machine will be analyzed at a time. I would like to extract the price associated with the item sold. I seem to be on the right track but I don't know how to fix this error.

    A1 shows product 0000(1.00) & A2 tells me 6 were sold.
    B1 & B2 (item 0002) work
    C1 does not work properly to tell me with item was sold in C2

    Again, any help would be appreciated. Thanks.
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    08-02-2013
    Location
    Québec
    MS-Off Ver
    Excel 2003, 2007, 2013
    Posts
    1,412

    Re: Extract substring if condition is met

    Hello Jefe,

    I'm not sure what the problem is with your formulas, but here's a suggestion using a macro:

    Sub SalesAnalysis()
       Dim ar, Dic, a, b
       Dim i As Integer, j As Integer, str
          
       Set Dic = CreateObject("scripting.dictionary")
       
       With Sheets("Sales")
          ar = .Range("H1:H" & .Cells(.Rows.Count, 8).End(xlUp).Row)
          For i = 1 To UBound(ar, 1)
             str = Replace(ar(i, 1), " ", "")
             str = Split(str, ",")
             For j = LBound(str) To UBound(str)
                a = "'" & Split(str(j), "(")(0)
                If Not Dic.exists(a) Then
                   Dic.Add a, 1
                Else
                   Dic(a) = Dic(a) + 1
                End If
             Next j
          Next i
          
          a = Dic.keys
          b = Dic.items
          
          With .Range("P1")
             .Resize(UBound(a) + 1, 1) = Application.Transpose(a)
             .Offset(0, 1).Resize(UBound(a) + 1, 1) = Application.Transpose(b)
          End With
       End With
    End Sub
    GC Excel

    If this post helps, then click the star icon (*) in the bottom left-hand corner of my post to Add reputation.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Extract data based on multiple substring criteria
    By jspharriola in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 10-10-2013, 01:50 AM
  2. [SOLVED] Extract a substring with find and mid
    By AlexRoberts in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 08-08-2013, 04:02 AM
  3. Extract variable length substring from a string
    By charron9 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 05-24-2013, 11:52 AM
  4. [SOLVED] extract from string whole word(s) containing substring
    By Bearpecs in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 09-24-2012, 10:37 AM
  5. [SOLVED] Extract Substring, then Ignore that Substring, while collecting data from Other substrings
    By Sameki121 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-17-2012, 05:21 PM
  6. Extract a substring with formula
    By bobwachs in forum Excel General
    Replies: 2
    Last Post: 09-10-2010, 04:47 PM
  7. Extract each substring from current cell
    By clickcoder in forum Excel General
    Replies: 6
    Last Post: 02-16-2010, 10:48 AM
  8. Extract 1st matching substring from cell
    By mtgiles in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 11-26-2008, 03:34 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1