Consulting

Results 1 to 4 of 4

Thread: Arrangement of values in groups

  1. #1
    VBAX Regular
    Joined
    Aug 2017
    Posts
    57
    Location

    Arrangement of values in groups

    Hi Everybody,

    I have a set of values, each start with a letter (either A,B,C or D), and a number after that as can be seen in the example worksheet attached. I want to group them according to the first letter they start with. I made an example in the attached worksheet. There are some formulas for this type of work but they don't work in this case. I'd really appreciate any help. Thanks!!


    Example-arrangementofvalues.xlsm

    example.jpg
    Last edited by Mati44; 02-02-2018 at 12:49 PM.

  2. #2
    VBAX Regular
    Joined
    Aug 2017
    Posts
    57
    Location
    any ideas, please?

  3. #3
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,728
    Location
    Not elegant

    Option Explicit
    
    Sub MoveData()
        Dim r As Long, c As Long, iStartCol As Long, n As Long
        
        With ActiveSheet
            For r = 2 To .Cells(1, 1).CurrentRegion.Rows.Count
                For c = 1 To .Cells(1, 1).CurrentRegion.Columns.Count
                    Select Case Left(.Cells(r, c).Value, 1)
                        Case "A"
                            iStartCol = 8
                        Case "B"
                            iStartCol = 13
                        Case "C"
                            iStartCol = 18
                        Case "D"
                            iStartCol = 23
                    End Select
            
            
                    For n = iStartCol To iStartCol + 5
                        If Len(.Cells(r, n).Value) = 0 Then
                            .Cells(r, n).Value = .Cells(r, c).Value
                            Exit For
                        End If
                    Next n
                Next c
            Next r
        End With
    
    End Sub
    Attached Files Attached Files
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  4. #4
    VBAX Regular
    Joined
    Aug 2017
    Posts
    57
    Location
    Thanks a lot, Paul! I was expecting a formula but now I will use this. If there is a formula solution coming up, i will be open for that too.

Posting Permissions

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