vba - How can I Extract only the text from cells which are formatted in a specific way. (excel) -
hi wonder if can help. importing html file places text first column of spreadsheet. text appear formated in various ways example may of colour or in italics, bold or combination.
is there way extract various text column based upon it's format , copy text column vba? please see example below of achieve.
many in advance.
you may start code
option explicit sub main() dim cell range dim word variant, coloff variant dim coloffstrng string worksheets("mysheet") '<~~ change "mysheet" whatever name sheet has each cell in .range("a4:a" & .cells(.rows.count, 1).end(xlup).row).specialcells(xlcelltypeconstants, xltextvalues) '<~~consider cells in column row 4 last non empty cell containing text values each word in split(worksheetfunction.trim(cell)) '<~~ check each word in cell. space assumed words separator, multiple spaces considered 1 space coloffstrng = "" '<~~ initialize offsets string cell.characters(instr(cell, word), len(word)).font '<~~ consider font property of word first character if .bold coloffstrng = coloffstrng & "1 " '<~~ bold 1 column offset column if .italic coloffstrng = coloffstrng & "2 " '<~~ italic 2 columns offset column select case .colorindex '<~~ consider colorindex property of word first character case 3 'red coloffstrng = coloffstrng & "3 " '<~~ red 3 columns offset column case 5 'blue coloffstrng = coloffstrng & "4 " '<~~ blue 4 columns offset column end select end each coloff in split(trim(coloffstrng)) '<~~ loop through each column offset stored cell.offset(, coloff) = word '<~~ fill proper cell word next coloff next word next cell end end sub
where assumed following:
all characters of each word share same formatting
formatting style columns are:
column b bold words
column c italic words
column d red words (colorindex = 3)
column e blue words (colorindex = 5)
for combination may use formulas directly typed in cells, like
=if(c4=d4,c4,"")
in cell h4, put combination of "italic" , "red" formatting
of course "combination" can furtherly automatized, perhaps boolean algebra
Comments
Post a Comment