Consulting

Results 1 to 5 of 5

Thread: Solved: Recognize mutiples and add rows

  1. #1

    Solved: Recognize mutiples and add rows

    I am sub-beginner in VBA-my boss wants me to learn a little basic programming so I thought this would be a good place to start. I am not sure if I can complete this task with a macro or what...Excell 2007I get an automatic excel report that lists a code or codes an individual has used; I want to know how to tell the program to recognize if there is multiple codes in a cell (always seperated by a comma) and if there is multiple codes, add an individual row for every individual code. Hopefully my attachment helps; 2 tabs.I hope I am clear enough; I think if I can get this, I will be able to build so much off of it.Thanks.
    Attached Files Attached Files

  2. #2
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    hi and wellcome to VBAX.

    try below code with a copy of your workbook.

    [VBA]Sub StringSplit()
    Dim varString As Variant
    Dim i As Integer, lrow As Long, rowIns As Long

    lrow = 2
    Do
    varString = Split(Replace(Cells(lrow, "C").Value, " ", ""), ",")
    If LBound(varString) = UBound(varString) Then
    Else
    rowIns = UBound(varString) - LBound(varString)
    Cells(lrow, "C").Offset(1).Resize(rowIns).EntireRow.Insert
    Cells(lrow, "C").Resize(rowIns + 1, 1) = Application.Transpose(varString)
    End If
    lrow = lrow + 1
    Loop Until Cells(lrow, "C") = ""
    End Sub
    [/VBA]
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Public Sub ProcessData()
    Dim vecCodes As Variant
    Dim Lastrow As Long
    Dim Numrows As Long
    Dim i As Long

    Application.ScreenUpdating = False

    With ActiveSheet

    Lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row
    For i = Lastrow To 2 Step -1

    If InStr(.Cells(i, "C").Value, ",") > 0 Then

    vecCodes = Split(.Cells(i, "C").Value, ",")
    Numrows = UBound(vecCodes) - LBound(vecCodes) + 1
    .Rows(i + 1).Resize(Numrows - 1).Insert
    .Cells(i, "C").Resize(Numrows) = Application.Transpose(vecCodes)
    End If
    Next i
    End With

    Application.ScreenUpdating = True

    End Sub[/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  4. #4
    Worked like a charm! Thanks for being so helpful and welcoming.

  5. #5
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    you are wellcome jrbuno.

    pls mark the thread as solved from thread tools dropdown...
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

Posting Permissions

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