+ Reply to Thread
Results 1 to 4 of 4

is it possible to determine parts of a string inside a cell and make an argument?

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    12-03-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    107

    is it possible to determine parts of a string inside a cell and make an argument?

    here is my code, explanation below:

    Select Case cells(1,1).value
        Case "125/240"
            Part_Number = "125"
        Case "100/380"
            Part_Number = "100"
        Case "80/250"
            Part_Number = "080"
        Case "63/125"
            Part_Number = "063"
        ' hundreds of other cases are written below
    end select
    I need a more efficent way of getting the part number. cells(1,1) is a cell where the system inputs a catalogue number for a certain unit. The part number is the number before the "/". I need to extract the part number from cell(1,1). I also need to add the zeroes for example 63/125 would be "065" and 80/250 would be "080"


    So i need an argument that's something like this:

    Get the number before the "/" inside the string and label it as the Part_Number.
    Let X be the number of digits after "/"
    Let Y be the number of digits before "/"
    X-Y = number of Zeroes to add before the part number


    Is VBA capable of doing this? It seems impossible =\...
    Last edited by kjy1989; 10-08-2013 at 03:30 AM.

  2. #2
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: is it possible to determine parts of a string inside a cell and make an argument?

    May be try like this...

    Sub GetPartOfTheNumber()
    
    With Cells(1, 1)
        Part_Number = Format(Left(.Value, InStr(.Value, "/") - 1), "000")
    End With
    
    MsgBox Part_Number
    
    End Sub


    If your problem is solved, then please mark the thread as SOLVED>>Above your first post>>Thread Tools>>
    Mark your thread as Solved


    If the suggestion helps you, then Click *below to Add Reputation

  3. #3
    Forum Contributor
    Join Date
    12-03-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    107

    Re: is it possible to determine parts of a string inside a cell and make an argument?

    Hi Sixthsense,

    Thank for your reply, i appreciate it. It's almost the right answer i was looking for except for one problem. The zero before the number should only happen if the number on the right is greater than one or more digits. for example:

    80/90 would show part number of 80
    80/100 would show a part number of 080 (because the number on the right is 100)
    80/1000 would be 0080 (because the number on the right is 1000)

    something like that...

  4. #4
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,711

    Re: is it possible to determine parts of a string inside a cell and make an argument?

    Try
    Sub test()
        Dim Part_Number
        With Cells(1, 1)
            Part_Number = Split(.Value, "/")(0)
            If .Value Like "*/*" Then
                Part_Number = Format$(Split(.Value, "/")(0), String(Len(Split(.Value, "/")(1)), "0"))
            End If
        End With
        MsgBox Part_Number
    End Sub

+ 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. Replies: 3
    Last Post: 01-22-2013, 02:09 AM
  2. Split String into 4 Parts - Max 30 Characters per Cell and Whole Words
    By keithm_007 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 11-22-2012, 05:56 AM
  3. Replies: 7
    Last Post: 07-01-2012, 05:43 PM
  4. Determine the current cell while inside a User Defined Function
    By pmax in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-01-2006, 07:50 PM
  5. [SOLVED] Function (array argument, range argument, string argument) vba
    By Witek in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-24-2005, 11:07 AM

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