Selecting Cell Content Among Range of Cells Based on Text Format (e.g. Red Text or Yellow Background)

PKT

New Member
Joined
Mar 3, 2023
Messages
4
Office Version
  1. 2010
  2. 2007
  3. 2003 or older
Platform
  1. Windows
Hi,
I have a range of cells (A2:A5) with text. Of these range of cells, there is always ONE cell that has specific formatting (e.g. RED text, BOLD text, colored BACKGROUND, etc.).The text formatting varies based on the row. All other cells within this range on that specific ROW has black text.
I need to get the content of the cell that has the RED text and store it in cell A1.
Is there a function or formula that can do this in Excel? Thanks.

A1A2A3A4A5
strawberryappleorangebananastrawberry
footballbaseballfootballbasketballsoccer

A1A2A3A4A5
strawberryappleorangebananastrawberry
footballbaseballfootballbasketballsoccer

A1A2A3A4A5
strawberryappleorangebananastrawberry
footballbaseballfootballbasketballsoccer
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
I would say doable with vba. You'd have to clarify whether or not any formatting causes the cell value to be placed in A1 or just certain formatting. So if it's anything but normal it shouldn't be too hard, but if it's based on this, this, this and this but not that, then that is important. Also important is the understanding of the range involved. If it is just A1 to A5 that is not the same as A1:X255 (or the range varies) for example.
 
Upvote 0
I would say doable with vba. You'd have to clarify whether or not any formatting causes the cell value to be placed in A1 or just certain formatting. So if it's anything but normal it shouldn't be too hard, but if it's based on this, this, this and this but not that, then that is important. Also important is the understanding of the range involved. If it is just A1 to A5 that is not the same as A1:X255 (or the range varies) for example.O

I would say doable with vba. You'd have to clarify whether or not any formatting causes the cell value to be placed in A1 or just certain formatting. So if it's anything but normal it shouldn't be too hard, but if it's based on this, this, this and this but not that, then that is important. Also important is the understanding of the range involved. If it is just A1 to A5 that is not the same as A1:X255 (or the range varies) for example.
OMG, thanks so much for the quick response!
To answer your question, not any formatting, just one specific type of formatting (e.g. BOLD).
In this case let's say:
- the range of cell contains BOLD text
- the range will vary by rows but at maximum up to 50 columns (A2:A50)
Basically Column A1 should only select cell content from range of cells (A2:A50) that have BOLD text only.

A1A2A3A...A50
orange, strawberryappleorangebananastrawberry
baseball, football, soccerbaseballfootballbasketballsoccer
red, rose pinkblueredrose pinkorange
truetruefalse
<<formula that extracts bolded text from columns (A2:A50)>>
 
Upvote 0
That is slightly more complex because you want to concatenate in column A. However, your A's are column headers? If not then it's not what you show, it's
A1B1C1D1...AX1
Probably not important. You could try the following code. It looks a bit over-blown to me but it seems to work. Maybe someone else will provide a more condensed version.
VBA Code:
Sub findBold()
Dim rng As Range, cel As Range
Dim Lcol As Long, Lrow As Long, i As Integer
Dim str As String

On Error GoTo errHandler
With ActiveSheet
    Lcol = .Cells.Find("*", SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column
    Lrow = Cells.Find(What:="*", After:=Range("A1"), LookAt:=xlPart, LookIn:=xlFormulas, _
             SearchOrder:=xlByRows, SearchDirection:=xlPrevious, MatchCase:=False).Row
End With
Application.EnableEvents = False

i = 2
Set rng = Range(Cells(2, 2), Cells(Lrow, Lcol))
For Each Row In rng.Rows
    For Each cel In Row.Cells
        If Not cel Is Nothing And cel.Font.Bold Then str = str & cel.Value & ", "
    Next cel
    If Not str = "" Then
        str = Trim(str)
        str = Left(str, Len(str) - 1)
        Cells(i, 1) = str
        str = ""
    End If
    i = i + 1
Next Row

exitHere:
Application.EnableEvents = True
Exit Sub

errHandler:
MsgBox "Error " & Err.Number & ": " & Err.Description
Resume exitHere

End Sub
 
Upvote 0
Hi again @Micron, thanks so much for the VBA code!
Yes, the top row is a header row... sorry for the confusion.

On another note, is it possible for this VBA to work with an argument where I can enter various range of cells (e.g. =FindBold(B1:Z1), or =FindBold(B2:Z2), etc...?
So that I can 'drag' the function/formula/VBA down a column? Thanks so much!

A1B1C1D1Z1
orange, strawberry
(e.g. =FindBold(B1:Z1))
appleorangebananastrawberry
baseball, football, soccer
(e.g. =FindBold(B2:Z2))
baseballfootballbasketballsoccer
red, rose pink
(e.g. =FindBold(B3:Z3))
blueredrose pinkorange
true
(e.g. =FindBold(B4:Z4))
truefalse
=FindBold(B99:Z99)
 
Upvote 0
I can think of 3 ways.
1) A range input box. That pops up, you select a range and click OK on the input and then the code runs.
2) Selection_Change event, but unless you restrict it to a column or row, it would fire every time you select a different cell.
3) userform, but more complicated when the range input should be able to do the same thing

My answers can't be more focused because I don't know the sheet structure or what user actions you might want to use to run the code.
 
Upvote 0

Forum statistics

Threads
1,224,603
Messages
6,179,850
Members
452,948
Latest member
UsmanAli786

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