Details of formatted cell

HaworthEstates

New Member
Joined
Jan 9, 2021
Messages
10
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
  2. MacOS
Hello there

I need some help with a problem:
I have a table, imported by Copy/Paste function, like the one below:
1610210556930.png


The values in column C and D are manually inserted, for the purpose of the problem.
How can I get these values (Column C and D) in an automation mode (functions or VBA)?

Many thanks in advance
Haworth
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Hi & welcome to MrExcel.
How about
VBA Code:
Sub HaworthEstates()
   Dim Cl As Range
   
   For Each Cl In Range("A2", Range("A" & Rows.Count).End(xlUp))
      Cl.Offset(, 2).Value = Cl.Font.FontStyle
      Cl.Offset(, 3).Value = GetHexFromLong(Cl.Font.Color)
   Next Cl
End Sub
Function GetHexFromLong(lngColour As Long) As String
   Dim R As String, G As String, B As String

   R = Format(Application.Dec2Hex(lngColour Mod 256), "00")
   G = Format(Application.Dec2Hex((lngColour \ 256) Mod 256), "00")
   B = Format(Application.Dec2Hex(lngColour \ 65536), "00")
   
   GetHexFromLong = "#" & R & G & B
End Function
 
Upvote 0
Hi & welcome to MrExcel.
How about
VBA Code:
Sub HaworthEstates()
   Dim Cl As Range
  
   For Each Cl In Range("A2", Range("A" & Rows.Count).End(xlUp))
      Cl.Offset(, 2).Value = Cl.Font.FontStyle
      Cl.Offset(, 3).Value = GetHexFromLong(Cl.Font.Color)
   Next Cl
End Sub
Function GetHexFromLong(lngColour As Long) As String
   Dim R As String, G As String, B As String

   R = Format(Application.Dec2Hex(lngColour Mod 256), "00")
   G = Format(Application.Dec2Hex((lngColour \ 256) Mod 256), "00")
   B = Format(Application.Dec2Hex(lngColour \ 65536), "00")
  
   GetHexFromLong = "#" & R & G & B
End Function
Thank you so much. The Problem is the function report font as "Regular" for all cells!
Can you help me with this one?

Thanks a lot.
 
Upvote 0
Is the font style & colour set manually, or by conditional formatting?
 
Upvote 0
Does it give the right colour?
As it works for me
+Fluff v2.xlsm
ABCD
1Name
2John Doe 1Bold#FF0000
3John Doe 2Italic#000000
4John Doe 3Bold Italic#B1A0C7
5John Doe 4Regular#000000
6John Doe 5Regular#000000
7John Doe 6Italic#FF0000
8John Doe 7Bold Italic#00B0F0
9John Doe 8Regular#000000
10John Doe 9Regular#FFC000
11John Doe 10Bold#DA9694
Data
 
Upvote 0
Is the font style & colour set manually, or by conditional formatting?
Sorry for the previous reply. The data is copied from a report on the web. While pasting into the excel worksheet, it shows the fonts as Bold or Regular, but on direct inspection all of them are Regular.
The color extraction works perfectly.
 

Attachments

  • Screenshot 2021-01-14 111346.jpg
    Screenshot 2021-01-14 111346.jpg
    113 KB · Views: 6
Upvote 0
Not sure if this will make a difference
VBA Code:
Sub HaworthEstates()
   Dim Cl As Range
   
   For Each Cl In Range("A2", Range("A" & Rows.Count).End(xlUp))
      Cl.Offset(, 2).Value = Cl.DisplayFormat.Font.FontStyle
      Cl.Offset(, 3).Value = GetHexFromLong(Cl.Font.Color)
   Next Cl
End Sub
 
Upvote 0
Not sure if this will make a difference
VBA Code:
Sub HaworthEstates()
   Dim Cl As Range
  
   For Each Cl In Range("A2", Range("A" & Rows.Count).End(xlUp))
      Cl.Offset(, 2).Value = Cl.DisplayFormat.Font.FontStyle
      Cl.Offset(, 3).Value = GetHexFromLong(Cl.Font.Color)
   Next Cl
End Sub
Not working, but it is fine. I came across another way to calculate, regardless of the Font properties. Still, I will use the color function, which helps me a lot.
THANK YOU.
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,219
Messages
6,123,690
Members
449,117
Latest member
Aaagu

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