Selecting cells with same formatting

psaulm119

Board Regular
Joined
Apr 6, 2007
Messages
67
I have a spreadsheet that I keep with a variety of text items. I use this when making an exam, and I only want to select some of the items to be on the test. I typically make my choices by applying boldprint formatting. Is there a way to select all instances in a worksheet with boldprint formatting? I believe I have seen a download/add-on for Excel that allows this, but I'd rather just learn to do it manually if its not too much trouble, and if its possible.
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Try

Code:
Sub SelectBold()
Dim c As Range, r As Range
For Each c In ActiveSheet.UsedRange
    If c.Font.Bold Then
        If r Is Nothing Then
            Set r = c
        Else
            Set r = Union(r, c)
        End If
    End If
Next c
If Not r Is Nothing Then r.Select
End Sub
 
Upvote 0
VoG, thanks for your code. I tried this, but after running the macro, I was told that I couldn't copy the selected text.

You see, what I want to do is copy the selected text, then paste it (unformatted text) onto a Word doc.

Is there a macro that will allow me to do that?
 
Upvote 0
You cannot copy multiple selections. What you can do is copy one area at a time and paste it into a contiguous range elsewhere on the sheet. For example

Code:
Sub SelectBold()
Dim c As Range, r As Range, Area As Range
For Each c In ActiveSheet.UsedRange
    If c.Font.Bold Then
        If r Is Nothing Then
            Set r = c
        Else
            Set r = Union(r, c)
        End If
    End If
Next c
If Not r Is Nothing Then
    For Each Area In r.SpecialCells(xlCellTypeConstants)
        Area.Copy Destination:=Range("H" & Rows.Count).End(xlUp).Offset(1)
    Next Area
End If
End Sub
 
Upvote 0
Great. I think that works. For any who want to use this code, if you look you can see that it will automatically paste a column with all of the worksheet's boldprint text onto a new column, H. This was a bit awkward, as occasionally I have text in column H, so I changed the macro code to paste it in column A (all I did was edit the macro, and change uppercase H to uppercase A).

Works like a charm. I only have 4 spreadsheets that I use constantly for this, so I'll save this macro in each of those spreadsheets.

Thanks again.

You cannot copy multiple selections. What you can do is copy one area at a time and paste it into a contiguous range elsewhere on the sheet. For example

Code:
Sub SelectBold()
Dim c As Range, r As Range, Area As Range
For Each c In ActiveSheet.UsedRange
    If c.Font.Bold Then
        If r Is Nothing Then
            Set r = c
        Else
            Set r = Union(r, c)
        End If
    End If
Next c
If Not r Is Nothing Then
    For Each Area In r.SpecialCells(xlCellTypeConstants)
        Area.Copy Destination:=Range("H" & Rows.Count).End(xlUp).Offset(1)
    Next Area
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,585
Messages
6,179,703
Members
452,938
Latest member
babeneker

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