+ Reply to Thread
Results 1 to 16 of 16

Fixing Bullet Lists with VBA Macro

Hybrid View

  1. #1
    Registered User
    Join Date
    06-08-2016
    Location
    Ann Arbor, Michigan, USA
    MS-Off Ver
    2013
    Posts
    8

    Fixing Bullet Lists with VBA Macro

    Hello,
    I'm compiling data and information from many Worksheets into one table, and some of the columns contain bullet lists, which have inconsistent formatting. I've created macros to trim those fields and remove all periods, but I'm having difficulty on the next step.

    I need code to find each bullet that isn't on its own row, and put it on its own row. Please help.

  2. #2
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Fixing Bullet Lists with VBA Macro

    Hi Craig,

    Can you provide some sample data that illustrates what exactly you want to do?
    Please help by:

    Marking threads as closed once your issue is resolved. How? The Thread Tools at the top
    Any reputation (*) points appreciated. Not just by me, but by all those helping, so if you found someone's input useful, please take a second to click the * at the bottom left to let them know

    There are 10 kinds of people in this world... those who understand binary, and those who don't.

  3. #3
    Registered User
    Join Date
    06-08-2016
    Location
    Ann Arbor, Michigan, USA
    MS-Off Ver
    2013
    Posts
    8

    Re: Fixing Bullet Lists with VBA Macro

    Yes, here is an example of one of a field that needs to be fixed:

    • Provide proper PPE to operators such as safety glasses with side shields, face shield, welding jacket • Portable GFCI • Inspect wheel for cracks / defects before use • Tongue guard in place and adjusted to within 1/4" of wheel • Tool rest adjusted to within 1/8" of wheel • Clear face guard in place over wheel Hot work permit for spark created work

    I want to automate the process of putting each of those bullet points on its own line within the field.

  4. #4
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Fixing Bullet Lists with VBA Macro

    By its own line, do you mean a carriage return so that it wraps to next line INSIDE the cell? or a new row on the spreadsheet?

  5. #5
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Fixing Bullet Lists with VBA Macro

    I just realized when you say "in its own line within the field" that you probably want to keep the text in ONE cell, just with a line feed/carriage return... If I am right then this code should to it?

    Option Explicit
    Sub craig_bickett()
    
    Dim ws As Worksheet
    Dim original_text() As String
    Dim new_text As String
    Dim lr As Long 'last row with data in the column you are fixing
    Dim i As Long
    Dim j As Long
    
    Set ws = Worksheets("Sheet1")
    lr = ws.Range("A" & Rows.Count).End(xlUp).Row 'change "A" to column with data to fix
    For i = lr To 1 Step -1 'assumes no headers, change the 1 to a 2 if you do have headers
        new_text = vbNullString
        original_text = Split(ws.Range("A" & i).Value, "•") 'replace "A" with correct column
        For j = 1 To UBound(original_text)
            If j < UBound(original_text) Then
                new_text = new_text & "•" & original_text(j) & vbCrLf
            Else
                new_text = new_text & "•" & original_text(j)
            End If
        Next j
        ws.Range("A" & i).Value = new_text 'again, replace "A" with the column
    Next i
    Set ws = Nothing
    
    End Sub

  6. #6
    Registered User
    Join Date
    06-08-2016
    Location
    Ann Arbor, Michigan, USA
    MS-Off Ver
    2013
    Posts
    8

    Re: Fixing Bullet Lists with VBA Macro

    We have a winner! Thank you very much!
    I'm having difficulty figuring out which part of your code is making the double-space.
    Some of the bullets were already on their own rows, and some were not. I'm assuming this is finding each bullet, and putting it on a new carriage return?
    If so, would it work to just add Also clause after the first If?

  7. #7
    Registered User
    Join Date
    06-08-2016
    Location
    Ann Arbor, Michigan, USA
    MS-Off Ver
    2013
    Posts
    8

    Re: Fixing Bullet Lists with VBA Macro

    Also, am I correct in assuming vbCrLf is a carriage return character that works similar to Chr(10) and Chr(13) used together?

  8. #8
    Registered User
    Join Date
    06-08-2016
    Location
    Ann Arbor, Michigan, USA
    MS-Off Ver
    2013
    Posts
    8

    Re: Fixing Bullet Lists with VBA Macro

    Nevermind, Find/Replace does just fine.

  9. #9
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Fixing Bullet Lists with VBA Macro

    craig,

    Glad you got it solved
    yes vbcrlf is as you assumed.

    Cheers,

    Arkadi

  10. #10
    Registered User
    Join Date
    06-08-2016
    Location
    Ann Arbor, Michigan, USA
    MS-Off Ver
    2013
    Posts
    8

    Re: Fixing Bullet Lists with VBA Macro

    If you're still willing to help, I have a couple more questions. There are another two problems I need to solve, and there is one thing I'm not seeing in this code.

    First off, the other two problems. Some of the fields with the bullet lists in the columns I'm correcting do not use bullets. Some have numbers and some just used double spacing to separate items of their list. Those are the only two other formats I need to worry about. The number lists may run into double-digits.

    The one thing I'm not seeing in the code is why the other two list formats are causing the macro to clear the contents of the field.

    I combined your code with the code I was using to trim. Here's the macro I'm still trying to fix:

    Sub CleanSpacesA()

    Dim sht As Worksheet
    Dim original_text() As String
    Dim new_text As String
    Dim lr As Long
    Dim i As Long
    Dim j As Long

    Set sht = Worksheets("Sheet1")

    lr = sht.Range("A" & Rows.Count).End(xlUp).Row 'replace with correct column

    i = 1

    For i = 1 To lr
    With Range("A" & i) 'replace with correct column
    .Value = WorksheetFunction.Trim(.Value)
    End With
    Next i

    For i = lr To 2 Step -1
    new_text = vbNullString
    original_text = Split(sht.Range("A" & i).Value, "•") 'replace with correct column
    For j = 1 To UBound(original_text)
    If j < UBound(original_text) Then
    new_text = new_text & "•" & original_text(j) & vbCrLf
    Else
    new_text = new_text & "•" & original_text(j)
    End If
    Next j
    sht.Range("A" & i).Value = new_text 'replace with correct column
    Next i
    Set sht = Nothing

    End Sub

    Any advice?

  11. #11
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059
    Sorry not at a computer just now and while i have ideas, i like to test what i post. I will try to get back to you shortly... Tomorrow morning at the latest

  12. #12
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Fixing Bullet Lists with VBA Macro

    You say sometimes the list is itemized either by double spaces or by numbers.... are the ONLY double spaces in a cell there to divide items? If so, then we can use the same principle to split up those cells in a new loop, I don't know if you want bullets replacing the double spaces to standardize your list? I'm assuming yes... but I'll put in red the pieces to take out if you don't want the bullet put into those:

    Sub CleanSpacesA()
    
    Dim sht As Worksheet
    Dim original_text() As String
    Dim new_text As String
    Dim lr As Long
    Dim i As Long
    Dim j As Long
    
    Set sht = Worksheets("Sheet1")
    
    lr = sht.Range("A" & Rows.Count).End(xlUp).Row 'replace with correct column
    
    i = 1
    
    For i = 1 To lr
    With Range("A" & i) 'replace with correct column
    .Value = WorksheetFunction.Trim(.Value)
    End With
    Next i
    'separate bullet items into separate rows
    For i = lr To 2 Step -1
        new_text = vbNullString
        original_text = Split(sht.Range("A" & i).Value, "•") 'replace with correct column
        For j = 1 To UBound(original_text)
            If j < UBound(original_text) Then
                new_text = new_text & "•" & original_text(j) & vbCrLf
            Else
            new_text = new_text & "•" & original_text(j)
            End If
        Next j
        If UBound(original_text) > 0 Then sht.Range("A" & i).Value = new_text 'replace with correct column
    Next i
    'separate double space items into separate rows
    For i = lr To 2 Step -1
        new_text = vbNullString
        original_text = Split(sht.Range("A" & i).Value, "  ") 'replace with correct column
        For j = 1 To UBound(original_text)
            If j < UBound(original_text) Then
                new_text = new_text & "•" & original_text(j) & vbCrLf
            Else
            new_text = new_text & "•" & original_text(j)
            End If
        Next j
        If UBound(original_text) > 0 Then sht.Range("A" & i).Value = new_text 'replace with correct column
    Next i
    
    Set sht = Nothing
    
    End Sub
    Please check out the forum rules, it will show you how to add code tags when you paste code so that things are easier to read.

    As far as numbers goes, that is a problem, since it is very hard for code to know which numbers are there for the listing of items, and which numbers are part of your valid text. Unless you can guarantee that numbers are ONLY ever used to separate list items and there are NO numbers at all that are part of normal text. Is there any extra criteria we can use to identify those?
    Last edited by Arkadi; 06-10-2016 at 09:20 AM.

  13. #13
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Fixing Bullet Lists with VBA Macro

    craig,

    First issue... the lack of bullets resulting in value gettting cleared:
    change this line of code:
    sht.Range("A" & i).Value = new_text 'replace with correct column
    with:
    If UBound(original_text) > 0 Then sht.Range("A" & i).Value = new_text 'replace with correct column
    this will omit pasting if there was nothing to split.
    Silly oversight on my part, I assumed there is always at least one bullet.

  14. #14
    Registered User
    Join Date
    06-08-2016
    Location
    Ann Arbor, Michigan, USA
    MS-Off Ver
    2013
    Posts
    8

    Re: Fixing Bullet Lists with VBA Macro

    Okay, I get why that works that way. Thank you. That pretty much solves my problem.

    There aren't many lists using numbers, so I'll just edit those manually.
    Last edited by craig.bickett; 06-10-2016 at 10:51 AM.

  15. #15
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059
    Quote Originally Posted by craig.bickett View Post
    Okay, I get why that works that way. Thank you. That pretty much solves my problem.

    There aren't many lists using numbers, so I'll just edit those manually.
    Instead of " " in the split code for double space you would put chr(10) without quotes:

    Split(sht.Range("A" & i).Value, Chr(10))
    Last edited by Arkadi; 06-10-2016 at 11:26 AM.

  16. #16
    Registered User
    Join Date
    06-08-2016
    Location
    Ann Arbor, Michigan, USA
    MS-Off Ver
    2013
    Posts
    8

    Re: Fixing Bullet Lists with VBA Macro

    Everything is working great. Thanks wizard man.

+ 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] Fixing Update Macro
    By bgrish3 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-31-2016, 12:37 PM
  2. Macro fixing background color after using cf
    By Jhon Mustofa in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-17-2014, 10:06 AM
  3. Bullet point and sub bullet points with numbers
    By trumpetman in forum Word Formatting & General
    Replies: 3
    Last Post: 12-17-2012, 12:23 PM
  4. Help please fixing a macro
    By tyleromaha in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-09-2012, 12:07 PM
  5. Need help fixing macro
    By Kb24 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-23-2009, 03:19 AM
  6. Fixing SSN's with a macro
    By Bruce Martin in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-18-2005, 02:05 AM
  7. [SOLVED] Fixing a macro
    By Tim Dolan in forum Excel General
    Replies: 13
    Last Post: 01-18-2005, 11:06 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