0

What I want to do is the following: I have around ~1400 rows full of data, of which the last column contains a lot of text. Here's an image to show what I mean: image removed because I can only post 2 links at once.

Now, to make that text easier to read, I want to bold some words of it.

Right now I have the following macro:

Dim range As range
Set range = Application.Selection

Dim boldwords As Variant
boldwords = Array("Atemschutz:", "Körperschutz:", "Handschutz:", "Augenschutz:")


Dim cell As range
For Each cell In range
    For Each bword In boldwords
        foundword = InStr(1, cell.Text, bword, VbCompareMethod.vbTextCompare)
        If foundword <> 0 Then
            cell.Characters(foundword, Len(bworld)).Font.Bold = True
        End If
    Next
Next
  1. Loop through all cells selected
  2. loop through all the words that should be bolded and check if they are contained in the cell
  3. If they are, bold them

Now my Problem is, once I run it my text either gets bolded completely or gets garbled Like this , or it places every letter on a separate line. Excel either slows down, freezes or sometimes crashes after that.

What can be done to prevent this?

UPDATE: After correcting the variable name Siphor mentioned, the text is no longer garbled but still gets split into separate lines sometimes, here's an image to show what I mean: click me

0

I think its a bug in your code, Len(bworld) should be Len(bword). You should enable Variable declaration required(Option Explicit) in the Vba options. It helps finding such bugs.

2
  • That was it. Didn't expect one character to break everything so hard. I'll keep that in mind now.
    – Lett1
    Aug 12 '14 at 10:47
  • UPDATE: While the tiny text bug seems fixed, the one where the word gets split into separate lines still persists. I added a picture of it to my question.
    – Lett1
    Aug 12 '14 at 10:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.