Comparar Celdas

 La siguiente macro compara celdas utilizando dos ciclos, un ciclo para las filas y otro ciclo para las columnas.


Macro:

-----------------------

Sub compararceldas()
'Por Dante Amor
  Dim i As Long, j As Long
  
  For i = 5 To Range("F" & Rows.Count).End(3).Row
    For j = 6 To 10
      If Cells(i, j) <> "no vengo" Then
        Cells(i, j) = "clásico"
      End If
      If Cells(i, j + 5) <> "no vengo" Then
        Cells(i, j + 5) = "postre"
      End If
    Next
  Next
End Sub

-----------------------

Macro para borrar rangos de celdas

-------------------

Sub borrar_rangos()
'Por Dante Amor
  Dim i As Long, j As Long
  Dim rng As Range
  
  For i = 2 To 120 Step 7
    For j = 1 To Columns("E").Column Step 2
      If rng Is Nothing Then
        Set rng = Cells(i, j).Resize(3)
      Else
        Set rng = Union(rng, Cells(i, j).Resize(3))
      End If
    Next
  Next
  rng.ClearContents
End Sub

-------------------

Macro para hacer suma y eliminar columnas:

------------------

Sub suma_columnas()
  Dim i As Long, j As Long
  Dim f As Range
  
  Application.ScreenUpdating = False
  Set f = Range("A:Y").Find("*", , xlValues, xlPart, xlByRows, xlPrevious)
  If Not f Is Nothing Then
    i = f.Row + 1
    With Range("A" & i).Resize(1, 25)
      .Formula = "=SUM(A1:A" & i - 1 & ")"
      .Value = .Value
    End With
    For j = 25 To 1 Step -1
      If Cells(i, j).Value = 0 Then
        Columns(j).EntireColumn.Delete
      End If
    Next
  End If
  Application.ScreenUpdating = True
End Sub
------------------

Código en el UserForm para activar el OptionButton

-----------------

Private Sub ListBox1_Click()
  If ListBox1.List(ListBox1.ListIndex, 4) = "Ingresos" Then
    OptionButton1.Value = True
  Else
    OptionButton2.Value = True
  End If
End Sub


----------------


Consejos para empezar a programar macros:




Saludos

Dante Amor

No hay comentarios.:

Publicar un comentario