Skip to content

Instantly share code, notes, and snippets.

@mbustamanteo
Created December 14, 2012 18:24
Show Gist options
  • Save mbustamanteo/4287469 to your computer and use it in GitHub Desktop.
Save mbustamanteo/4287469 to your computer and use it in GitHub Desktop.
Macro para reemplazar las formulas por sus valores segun los colores de celda
Sub CopiarPegarValores()
'
' Esta macro lo que hace es reemplazar las formulas
' por sus valores a todas las celdas de un determinado valor
'
'
' .Color = 15986394 ' celda azul para las formulillas
'
Dim celda As Range ' la celda actual
Dim color As Long ' color de la celda
Dim colorABuscar As Long ' color de la celda que estamos buscando
Dim rangoAModificar As Range ' rango de los datos
colorABuscar = 15986394
Set rangoAModificar = Range("A1:AQ300")
Range("A1").Select
Application.FindFormat.Clear
ActiveSheet.EnableCalculation = False
With Application.FindFormat.Interior
.color = colorABuscar
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
End With
Set celda = rangoAModificar.Find(What:="", after:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=True)
If Not celda Is Nothing Then
firstAddress = celda.Address
Do
celda.Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Set celda = rangoAModificar.Find(What:="", after:=celda, SearchFormat:=True)
Loop While Not celda Is Nothing And celda.Address <> firstAddress
Else
Debug.Print "No se ha modificado nada"
End If
ActiveSheet.EnableCalculation = True
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment