E' possibile cambiare solo il colore (in generale la formattazione) di una parola contenuta in molte celle Excel?
Faccio un esempio. Nelle celle di un foglio ci sono delle celle con queste frasi:
| (cella A1) numero porte patinate |
(cella B1) numero finestre finitura patinata |
(cella C1) finestre patinate |
| (cella A2) finitura patinata colorata |
(cella B2) porte patinate scorrevoli |
(cella C2) porte patinate battente |
| (...) totale porte e finestre |
(...) totale porte |
(...) totale finestre |
| (...) |
(...) |
(...) |
| (...) |
(...) |
(...) |
Quale comando (se con CTRL+SHIFT+S, quali opzioni settare) mi può trasformare la tabella così?
| (cella A1) numero porte patinate |
(cella B1) numero finestre finitura patinata |
(cella C1) finestre patinate |
| (cella A2) finitura patinata colorata |
(cella B2) porte patinate scorrevoli |
(cella C2) porte patinate battente |
| (...) totale porte e <br>finestre |
(...) totale porte |
(...) totale finestre |
Se effettuo Trova/Sostituisci, inserisco la parola "porte" e cambio colore (qui mi sono limitato a grassetto e corsivo, ma il mio intento è cambiare anche il colore) la sostituzione avviene,
ma la nuova formattazione si applica all'intera cella.
Come limitare ad una sola parola, senza alterare le altre proprietà della cella, come allineamento, colore sfondo, formattazione contenuto (numero, generale, testo, data/ora, ...), ecc ecc ...
Ciao Sebastiano,
Prova qualcosa del genere:
Alt-F11 per aprire l'editor di VBA
Alt-IM per inserire un nuovo modulo di codice
Nel nuovo modulo vuoto, incolla il seguente codice:
'==========>>
Option Explicit
'---------->>
Public Sub Tester()
Dim WB As Workbook
Dim SH As Worksheet
Dim Rng As Range, Rng2 As Range, Rng3 As Range, RngOut As Range
Dim rCell As Range
Dim sStr As String
Dim iPos As Long, jPos As Long, iLen As Long, jlen As Long
Const aStr As String = "porte" '<<==== Modifica
Const bStr As String = "finestre" '<<==== Modifica
Set WB = ActiveWorkbook
Set SH = WB.Sheets("Foglio2") '<<==== Modifica
Set Rng = SH.Range("A1:D100") '<<==== Modifica
On Error Resume Next
Set Rng2 = Rng.SpecialCells(xlCellTypeConstants, 2)
Set Rng3 = Rng.SpecialCells(xlCellTypeFormulas, 2)
On Error GoTo 0
If Not Rng2 Is Nothing Then
If Not Rng3 Is Nothing Then
Set RngOut = Union(Rng2, Rng3)
Else
Set RngOut = Rng2
End If
Else
If Not Rng3 Is Nothing Then
Set RngOut = Rng3
Else
Exit Sub
End If
End If
iLen = Len(aStr)
jlen = Len(bStr)
For Each rCell In Rng.Cells
sStr = rCell.Value
iPos = InStr(1, sStr, aStr, vbTextCompare)
jPos = InStr(1, sStr, bStr, vbTextCompare)
If CBool(iPos) Then
rCell.Characters(iPos, iLen).Font.Bold = True
End If
If CBool(jPos) Then
rCell.Characters(jPos, jlen).Font.Underline = True
End If
Next rCell
End Sub
'<<==========
Alt-Q per chiudere l'editor di VBA e tornare a Excel.
Alt-F8 per aprire la finestrina macro
Seleziona Tester | Esegui
===
Regards,
Norman