Convert cell styles (formatting) to values

KrsOne20

New Member
Joined
Dec 5, 2014
Messages
21
In my datasheet I have applied various styles to cells, each style (format) represents something as seen below. For example pink means press release (PR). However now I need to convert this data into a mastertable (which can be used to create pivots, or can be read into SPSS). The issue is that VLOOKUP (or match index) discards the formatting/styles when applied.

Is there a VBA code to convert the cell styles to values? For example data in cell A2 the code will insert 'CR', as that is the name of the style applied. Let me know! Thanks in advance


Example
5j1ygai.png


Cell styles

RCmF5ZY.png
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Were these colors chosen from the menu by users (i.e. there's no written "map" of conditions you can refer to)? In that case, find the color index with VBA and look that up from a table you build. If you have the criteria written out somewhere then it's even simpler.
 
Upvote 0
The style property in VBA (.style) should return the name

Thanks for your response. How can I adjust this formula below, so that when I enter the formula =A1 in cell A2, I get the style name in cell A2? (sorry Im a noob at creating VBA codes)

Code:
<code class="vb keyword">Function</code> <code class="vb plain">getRGB1(FCell </code><code class="vb keyword">As</code> <code class="vb plain">Range) </code><code class="vb keyword">As</code> <code class="vb keyword">String</code>

<code class="vb comments">'UpdatebyExtendoffice20170714</code>

<code class="vb spaces">    </code><code class="vb keyword">Dim</code> <code class="vb plain">xColor </code><code class="vb keyword">As</code> <code class="vb keyword">String</code>

<code class="vb spaces">    </code><code class="vb plain">xColor = </code><code class="vb keyword">CStr</code><code class="vb plain">(FCell.Interior.Color)</code>
<code class="vb spaces">    </code><code class="vb plain">xColor = Right(</code><code class="vb string">"000000"</code> <code class="vb plain">& Hex(xColor), 6)</code>

<code class="vb spaces">    </code><code class="vb plain">getRGB1 = Right(xColor, 2) & Mid(xColor, 3, 2) & Left(xColor, 2)</code>
<code class="vb keyword">End</code> <code class="vb keyword">Function</code>
 
Upvote 0
Something like:

Code:
Function getstyle(fcell As Range) As String
getstyle = fcell.Style
End Function

Hmm, I'm getting a error. It should show style 'IGD'. I indeed used the styles consistently, so it should show 'IGD'. However not a big deal, issue is also solved with RGB code. Thanks anyways for your input!

FSCKNHx.png
 
Upvote 0
You saved to a module and not a worksheet, right? Does this error persist even after rebooting?

It was already in a module. However I just re-added the code and it works! Weird that it does work now. I think the issue was the name of the module (earlier I renamed the module to getStyle).
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,179
Members
453,021
Latest member
Justyna P

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