Aplicar efecto superíndice o subíndice a determinadas palabras en texto concatenado en Excel

Código

Sub IB·AplicarEfecto()
Dim r As Range, x As Range, c As Range, p As Range, b() As String, h As Long, s As Integer
On Error Resume Next
Set r = Application.InputBox("Selecciona el rango donde se aplicará el cambio de efecto:", "INGENIERÍA & BURÓTICA", , Type:=8)
On Error GoTo 0
On Error Resume Next
Set x = Application.InputBox("Selecciona el rango con las palabras a cambiar el efecto:", "INGENIERÍA & BURÓTICA", , Type:=8)
On Error GoTo 0
s = InputBox("Seleccione el efecto deseado:" & vbCrLf & "2 para superíndice" & vbCrLf & "1 para subíndice", "INGENIERÍA & BURÓTICA", 1)
If s <> 1 And s <> 2 Then
MsgBox "efecto no válido. Use 1 para subíndice o 2 para superíndice."
Exit Sub
End If
If Not r Is Nothing And Not x Is Nothing Then
ReDim b(1 To x.Cells.Count)
Dim i As Integer
i = 1
For Each p In x
b(i) = p.Value
i = i + 1
Next p
For Each c In r
For i = LBound(b) To UBound(b)
If InStr(1, " " & c.Value & " ", " " & b(i) & " ") > 0 Then
Dim posInicio As Integer
posInicio = InStr(1, " " & c.Value & " ", " " & b(i) & " ")
If s = 1 Then
c.Characters(Start:=posInicio, Length:=Len(b(i))).Font.Subscript = True
Else
c.Characters(Start:=posInicio, Length:=Len(b(i))).Font.Superscript = True
End If
End If
Next i
Next c
Else
MsgBox "No se han seleccionado rangos válidos."
End If
End Sub

Comentarios