About Me
Com tecnologia do Blogger.
Seguidores
Estatisticas
2006-02-11
Num newsgroup, foi feita a seguinte pergunta: Será que é possivel num Range em que tenho números (1,2,3,4,5, etc.) acrescentar letras atrás (COL1,COL2,COL3,COL4,COL5, etc.) sem editar célula a célula?
Selecciona-se o Range pretendido:

Executa-se a macro:

O resultado:

O Código do exemplo, em VBA:
Option Explicit
Sub AdicionaTexto()
Dim rng As Range
Dim rngCell As Range
Const sCHARACTER As String = "COL"
On Error GoTo Exit_AdicionaTexto
Set rng = ActiveWindow.RangeSelection
For Each rngCell In rng.Cells
If IsEmpty(rngCell.Value) = False Then
rngCell.Value = sCHARACTER & rngCell.Value
End If
Next rngCell
Exit_AdicionaTexto:
Set rngCell = Nothing
Set rng = Nothing
End Sub
Selecciona-se o Range pretendido:

Executa-se a macro:

O resultado:

O Código do exemplo, em VBA:
Option Explicit
Sub AdicionaTexto()
Dim rng As Range
Dim rngCell As Range
Const sCHARACTER As String = "COL"
On Error GoTo Exit_AdicionaTexto
Set rng = ActiveWindow.RangeSelection
For Each rngCell In rng.Cells
If IsEmpty(rngCell.Value) = False Then
rngCell.Value = sCHARACTER & rngCell.Value
End If
Next rngCell
Exit_AdicionaTexto:
Set rngCell = Nothing
Set rng = Nothing
End Sub