Unificar código en uno solo

Como puedo unir estas dos macros y que quede en un solo código

'como puedo unir estas dos macros en una sola
Sub macro1()
  Sheets("actual").Range("A1").Value = Sheets("Hoja2").Range("H1").Value
End Sub
Private Sub SpinButton1_Change()  'hoja actual
  Dim n%, valor As String ' <= variable agregada '
  Application.ScreenUpdating = False
  If [A1] = "0000" Then Exit Sub
  valor = Format([A1], "0000") ' <= formato agregado '
  For i = 1 To Sheets.Count
    Sheets(i).Activate
    [A1] = valor
    For n = 1 To Len(valor)
      BuscarÁrea n, Mid(valor, n, 1), 4, 13
      BuscarÁrea n, Mid(valor, n, 1), 17, 26
    Next
  Next
End Sub

1 Respuesta

Respuesta
1

Prueba así:

Private Sub SpinButton1_Change()  'hoja actual
  Dim n%, valor As String ' <= variable agregada '
  Dim i As Long
  Application.ScreenUpdating = False
  With Sheets("actual")
    .Range("A1").Value = Sheets("Hoja2").Range("H1").Value
    If .[A1] = "0000" Then Exit Sub
    valor = Format(.[A1], "0000") ' <= formato agregado '
    For i = 1 To Sheets.Count
      Sheets(i).Activate
      [A1] = valor
      For n = 1 To Len(valor)
        BuscarÁrea n, Mid(valor, n, 1), 4, 13
        BuscarÁrea n, Mid(valor, n, 1), 17, 26
      Next
    Next
  End With
End Sub

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas