Checkbox con macro para combinar con otras macros
Dante Amor gracias por tu apoyo que me estas brindando, subo nuevamente la pregunta para que me apoyes con la macro que tiene la celda k5, como me consultabas, donde agrego tu código que creaste y el codigo que ya tiene el archivo
Macro Dante amor
Option Explicit
Private Sub CheckBox1_Click()
Call Filtrar
End Sub
Private Sub CheckBox2_Click()
Call Filtrar
End Sub
Private Sub CheckBox3_Click()
Call Filtrar
End Sub
'
Sub Filtrar()
Dim n As Long
Dim arr() As Variant
n = -1
If CheckBox1 Then
n = n + 1
ReDim Preserve arr(n)
arr(n) = "Transferencia con un Débito"
End If
If CheckBox2 Then
n = n + 1
ReDim Preserve arr(n)
arr(n) = "Transferencia con un Crédito"
End If
If CheckBox3 Then
n = n + 1
ReDim Preserve arr(n)
arr(n) = "Financiamiento"
End If
Call desproteger
Application.ScreenUpdating = False
If ActiveSheet.AutoFilterMode Then ActiveSheet.AutoFilterMode = False
If n > -1 Then
Range("A6", Range("L" & Rows.Count).End(3)).AutoFilter 12, Array(arr), xlFilterValues
End If
Application.ScreenUpdating = True
Call proteger
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
Dim f As Range
'
If Target.CountLarge > 1 Then Exit Sub
If Target.Address = "$K$5" Then
Call desproteger
Application.ScreenUpdating = False
If ActiveSheet.AutoFilterMode Then ActiveSheet.AutoFilterMode = False
If Target.Value <> "" Then
Set f = Range("B:B").Find(Target.Value, , xlValues, xlWhole)
If Not f Is Nothing Then
Range("A6", Range("L" & Rows.Count).End(3)).AutoFilter 1, Target.Value
Else
MsgBox "No existe el renglón presupuestario", vbInformation + vbOKOnly, "Aviso para Intecap"
Range("K5").ClearContents
End If
End If
Range("K5").Select
Application.ScreenUpdating = False
Call proteger
End If
End Sub
Sub proteger()
Worksheets("RENGLONES").Protect ("regional2018")
End Sub
Sub desproteger()
Worksheets("RENGLONES").Unprotect ("regional2018")
End Sub
Este es el código del módulo de funciones que ha tenido el archivo y que es la que hace el buscador en la celda k5
Public contraseña
'Sub Macro1()
' ActiveSheet.Range("$A$6:$I$785").AutoFilter Field:=1
'End Sub
Public rango As String, valorbuscado As String, contador As Double
Sub Encontrarvalores()
Dim resultado As Range
Dim primerabusqueda As String
'Dim contador As Double
valorbuscado = Hoja1.Range("$K$5").Value
Set resultado = Hoja1.Range("B6:B999").Find(valorbuscado, , xlValues, xlWhole, xlByColumns, xlNext, False, , False)
If resultado Is Nothing Then
'MsgBox "No se encontraron coincidencias."
Else
primerabusqueda = resultado.Address
Do
contador = contador + 1
Set resultado = Hoja1.Range("B6:B999").FindNext(resultado)
Loop While Not resultado Is Nothing And resultado.Address <> primerabusqueda
End If
End Sub
Sub mostrarhojas()
UserForm1.Show
If contraseña = "transferencia" Then
Worksheets(2).Visible = True
'Worksheets(3).Visible = True
'Worksheets(4).Visible = True
Else
MsgBox "Contraseña incorrecta, intenta de nuevo", vbCritical, "Debes ser usuario de INTECAP!!!"
End If
End Sub
'
Sub ocultarhojas()
UserForm1.Show
If contraseña = "transferencia" Then
Worksheets(2).Visible = False
'Worksheets(3).Visible = False
'Worksheets(4).Visible = False
'
Worksheets(2).Protect ("regional2018")
'Worksheets(3).Protect ("regional2018")
'Worksheets(4).Protect ("regional2018")
Else
MsgBox "Contraseña incorrecta, intenta de nuevo", vbCritical, "La Integración de Renglones no sera visible"
End If
End Sub
Gracias Dante por tu apoyo, estoy muy agradecida con tu persona