Add bullets to named range column

Sumeluar

Active Member
Joined
Jun 21, 2006
Messages
271
Office Version
  1. 365
  2. 2016
  3. 2010
Platform
  1. Windows
  2. MacOS
  3. Mobile
Good day! - I need help on modifying the code below to do the following:

On a named range from columns C to J, I would like to add a bullet only to any text entered on Column D6 and down, if any cells on column D already containing a bullet has to be ignored so not to end up with multiple bullets. The below code came from a google search, it works but the range (Column D) needs to be selected manually and any cells already containing a bullet and the code is reapplied end up with an additional one.

Sub Add_Bullets()
Dim cell As Range
Dim vntLines As Variant
Dim lngIndex As Long
Dim strTemp As String
Sheets("EventsList").Select
For Each cell In Selection.Cells
strTemp = ""
vntLines = Split(cell.Value, vbLf)
For lngIndex = LBound(vntLines) To UBound(vntLines)
If Len(Trim(vntLines(lngIndex))) > 0 Then
strTemp = strTemp & Chr(149) & " " & vntLines(lngIndex) & vbLf
Else
strTemp = strTemp & vbLf
End If
Next
cell.Value = Left(strTemp, Len(strTemp) - 1)
Next cell
End Sub

I appreciate any new suggestions or improvements to the above code.

Best Regards!
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Try this :
VBA Code:
Sub Add_Bullets()
Dim cell As Range
Dim vntLines As Variant
Dim lngIndex As Long
Dim strTemp As String
Sheets("EventsList").Select
Dim rng As Range
Set rng = Range([D6], Cells(Rows.Count, "D").End(3))
For Each cell In rng
    strTemp = ""
    vntLines = Split(cell.Value, vbLf)
    For lngIndex = LBound(vntLines) To UBound(vntLines)
        If Len(Trim(vntLines(lngIndex))) > 0 And Left(Trim(vntLines(lngIndex)), 1) <> Chr(149) Then
            strTemp = strTemp & Chr(149) & " " & vntLines(lngIndex) & vbLf
        Else
            strTemp = strTemp & vntLines(lngIndex) & vbLf
        End If
    Next
    cell.Value = Left(strTemp, Len(strTemp) - 1)
Next cell
End Sub
 
Upvote 0
Try this :
VBA Code:
Sub Add_Bullets()
Dim cell As Range
Dim vntLines As Variant
Dim lngIndex As Long
Dim strTemp As String
Sheets("EventsList").Select
Dim rng As Range
Set rng = Range([D6], Cells(Rows.Count, "D").End(3))
For Each cell In rng
    strTemp = ""
    vntLines = Split(cell.Value, vbLf)
    For lngIndex = LBound(vntLines) To UBound(vntLines)
        If Len(Trim(vntLines(lngIndex))) > 0 And Left(Trim(vntLines(lngIndex)), 1) <> Chr(149) Then
            strTemp = strTemp & Chr(149) & " " & vntLines(lngIndex) & vbLf
        Else
            strTemp = strTemp & vntLines(lngIndex) & vbLf
        End If
    Next
    cell.Value = Left(strTemp, Len(strTemp) - 1)
Next cell
End Sub
Footoo, thanks for the updated code, it works although having over a thousand cells it does take a while to go through the whole thing.

Regards!
 
Upvote 0
See if adding these two lines at the top and bottom of your code help speed it up:
VBA Code:
Sub Add_Bullets()

Application.ScreenUpdating = True
Application.Calculation = xlCalculationManual

Dim cell As Range
Dim vntLines As Variant
Dim lngIndex As Long
Dim strTemp As String
Sheets("EventsList").Select
Dim rng As Range
Set rng = Range([D6], Cells(Rows.Count, "D").End(3))
For Each cell In rng
    strTemp = ""
    vntLines = Split(cell.Value, vbLf)
    For lngIndex = LBound(vntLines) To UBound(vntLines)
        If Len(Trim(vntLines(lngIndex))) > 0 And Left(Trim(vntLines(lngIndex)), 1) <> Chr(149) Then
            strTemp = strTemp & Chr(149) & " " & vntLines(lngIndex) & vbLf
        Else
            strTemp = strTemp & vntLines(lngIndex) & vbLf
        End If
    Next
    cell.Value = Left(strTemp, Len(strTemp) - 1)
Next cell

Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True

End Sub
 
Upvote 0
Solution
See if adding these two lines at the top and bottom of your code help speed it up:
VBA Code:
Sub Add_Bullets()

Application.ScreenUpdating = True
Application.Calculation = xlCalculationManual

Dim cell As Range
Dim vntLines As Variant
Dim lngIndex As Long
Dim strTemp As String
Sheets("EventsList").Select
Dim rng As Range
Set rng = Range([D6], Cells(Rows.Count, "D").End(3))
For Each cell In rng
    strTemp = ""
    vntLines = Split(cell.Value, vbLf)
    For lngIndex = LBound(vntLines) To UBound(vntLines)
        If Len(Trim(vntLines(lngIndex))) > 0 And Left(Trim(vntLines(lngIndex)), 1) <> Chr(149) Then
            strTemp = strTemp & Chr(149) & " " & vntLines(lngIndex) & vbLf
        Else
            strTemp = strTemp & vntLines(lngIndex) & vbLf
        End If
    Next
    cell.Value = Left(strTemp, Len(strTemp) - 1)
Next cell

Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True

End Sub

Joe4 - That works flawless, thank you.

Big thanks to footoo as well.

Appreciate the quick and precise replies.

Best regards!
 
Upvote 0
Sumulear,

All I did was add these two lines at the top of the code:
VBA Code:
Application.ScreenUpdating = True
Application.Calculation = xlCalculationManual
and then these two lines at the bottom:
VBA Code:
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True

It doesn't change how the code runs, it just should speed it up by delaying the calculations and screen updates (you mentioned the code took a while to run).
Does it help it run any faster?
 
Upvote 0
Sumulear,

All I did was add these two lines at the top of the code:
VBA Code:
Application.ScreenUpdating = True
Application.Calculation = xlCalculationManual
and then these two lines at the bottom:
VBA Code:
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True

It doesn't change how the code runs, it just should speed it up by delaying the calculations and screen updates (you mentioned the code took a while to run).
Does it help it run any faster?
Joe4 - Both codes do the same thing but the first one literally would scroll down quite slowly. With the lines you added at the top and at the bottom it does run faster, I am fully satisfied how it runs.
 
Upvote 0
Joe4 - Both codes do the same thing but the first one literally would scroll down quite slowly. With the lines you added at the top and at the bottom it does run faster, I am fully satisfied how it runs.
Yes, that was exactly my intention. I did not change any of the body of the code. I simply added some lines to the top of the existing code that suppressing screen updates and calculations until the very end. This is a trick you can do on almost any VBA code that often helps speed it up.
 
Upvote 0

Forum statistics

Threads
1,215,256
Messages
6,123,912
Members
449,132
Latest member
Rosie14

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top