Consulting

Results 1 to 3 of 3

Thread: .pattern help please

  1. #1
    VBAX Newbie
    Joined
    Apr 2017
    Posts
    2
    Location

    .pattern help please

    i am newbie in vba, and trying to write a program can get values automatically, like the table below

    Column A:
    D1234/9525845/480.5/48/A --->column B: 480.5 ---->column C: 48
    peter/D12457(6)/50/$477/F --->column B: 477 --->column C: 50
    sam/520/6528457/$52 --->column B: 520 --->column C: 52
    B5214/50.5 --->column C: 50.5
    B52145/500 --->column B: 500

    what i want is to put the value under 1000 to column B, and the value under 100 to column C.
    i tried a lot with something like .pattern "[0-9]{3}", but it keeps give me the wrong value that i dont want, can someone please help, thanks.

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Sub Test()
        Dim arr, a
        Dim cel as Range
        For Each cel In Cells(1, 1).CurrentRegion
        arr = Split(Replace(cel, "$", ""), "/")
                On Error Resume Next
                For Each a In arr
                    If a < 1000 And a >= 100 Then cel.Offset(, 1) = a
                    If a < 100 Then cel.Offset(, 2) = a
                Next
        Next cel
    End Sub
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  3. #3
    VBAX Newbie
    Joined
    Apr 2017
    Posts
    2
    Location
    solved. thanks a lot !

Posting Permissions

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