У меня есть кнопки, которые устанавливают значение диапазона ячеек в галочку, найденную в другой ячейке. Затем с помощью Worksheet_Change (ByVal Target as Range) должен быть запущен другой макрос, поскольку в столбце, в котором находится макрос worksheet_change, найдены галочки. Он работает только для первой строки в диапазоне. Если отдельные ячейки изменяются вручную с помощью пользовательского ввода (выпадающий, который ссылается на ту же ячейку, содержащую флажок), то макрос работает нормально. Я знаю, что это будет работать без кнопок, но есть много ячеек, чтобы каждый пользователь мог выбрать каждый из них вручную.
Код для одной из кнопок:
Private s As Integer
Sub Button1_Click()
If s = 0 Then
Range("F5,F6:F14").Value = Range("ZZ2").Value
ActiveSheet.Shapes.Range(Array("Button 1")).Select
Selection.Characters.Text = "Uncheck All"
s = 1
ElseIf s = 1 Then
Range("F5,F6:F14").Value = Range("ZZ1").Value
ActiveSheet.Shapes.Range(Array("Button 1")).Select
Selection.Characters.Text = "Check All"
s = 0
End If
End Sub
Затем код для изменения в столбце:
Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$F$5" Then
If Range("$G$5") = True Then
If Range("I1").Value >= Range("H5").Value Then
Range("I5").Formula = "=$E5"
End If
If Range("J1").Value >= Range("H5").Value Then
Range("J5").Formula = "=$E5"
End If
If Range("K1").Value >= Range("H5").Value Then
Range("K5").Formula = "=$E5"
End If
If Range("L1").Value >= Range("H5").Value Then
Range("L5").Formula = "=$E5"
End If
If Range("M1").Value >= Range("H5").Value Then
Range("M5").Formula = "=$E5"
End If
If Range("N1").Value >= Range("H5").Value Then
Range("N5").Formula = "=$E5"
End If
If Range("O1").Value >= Range("H5").Value Then
Range("O5").Formula = "=$E5"
End If
If Range("P1").Value >= Range("H5").Value Then
Range("P5").Formula = "=$E5"
End If
If Range("Q1").Value >= Range("H5").Value Then
Range("Q5").Formula = "=$E5"
End If
If Range("R1").Value >= Range("H5").Value Then
Range("R5").Formula = "=$E5"
End If
If Range("S1").Value >= Range("H5").Value Then
Range("S5").Formula = "=$E5"
End If
If Range("T1").Value >= Range("H5").Value Then
Range("T5").Formula = "=$E5"
End If
ElseIf Range("G5") = False Then
Range("I5").Value = "=AF16"
Range("J5").Value = "=AG16"
Range("K5").Value = "=AH16"
Range("L5").Value = "=AI16"
Range("M5").Value = "=AJ16"
Range("N5").Value = "=AK16"
Range("O5").Value = "=AL16"
Range("P5").Value = "=AM16"
Range("Q5").Value = "=AN16"
Range("R5").Value = "=AO16"
Range("S5").Value = "=AP16"
Range("T5").Value = "=AQ16"
End If
End If
If Target.Column = 6 And Target.Row > 5 Then
ThisRow = Target.Row
Dim LValue As String
LValue = "=E" & ThisRow
If Range("G" & ThisRow) = True Then
If Range("I1").Value >= Range("H" & ThisRow).Value Then
Range("I" & ThisRow).Formula = LValue
End If
If Range("J1").Value >= Range("H" & ThisRow).Value Then
Range("J" & ThisRow).Formula = LValue
End If
If Range("K1").Value >= Range("H" & ThisRow).Value Then
Range("K" & ThisRow).Formula = LValue
End If
If Range("L1").Value >= Range("H" & ThisRow).Value Then
Range("L" & ThisRow).Formula = LValue
End If
If Range("M1").Value >= Range("H" & ThisRow).Value Then
Range("M" & ThisRow).Formula = LValue
End If
If Range("N1").Value >= Range("H" & ThisRow).Value Then
Range("N" & ThisRow).Formula = LValue
End If
If Range("O1").Value >= Range("H" & ThisRow).Value Then
Range("O" & ThisRow).Formula = LValue
End If
If Range("P1").Value >= Range("H" & ThisRow).Value Then
Range("P" & ThisRow).Formula = LValue
End If
If Range("Q1").Value >= Range("H" & ThisRow).Value Then
Range("Q" & ThisRow).Formula = LValue
End If
If Range("R1").Value >= Range("H" & ThisRow).Value Then
Range("R" & ThisRow).Formula = LValue
End If
If Range("S1").Value >= Range("H" & ThisRow).Value Then
Range("S" & ThisRow).Formula = LValue
End If
If Range("T1").Value >= Range("H" & ThisRow).Value Then
Range("T" & ThisRow).Formula = LValue
End If
ElseIf Range("G" & ThisRow) = False Then
Range("I" & ThisRow).Value = ""
Range("J" & ThisRow).Value = ""
Range("K" & ThisRow).Value = ""
Range("L" & ThisRow).Value = ""
Range("M" & ThisRow).Value = ""
Range("N" & ThisRow).Value = ""
Range("O" & ThisRow).Value = ""
Range("P" & ThisRow).Value = ""
Range("Q" & ThisRow).Value = ""
Range("R" & ThisRow).Value = ""
Range("S" & ThisRow).Value = ""
Range("T" & ThisRow).Value = ""
End If
End If
If Target.Column = 29 Then
ThatRow = Target.Row
Dim MValue As String
MValue = "=AX" & ThatRow
If Range("AD" & ThatRow) = True Then
If Range("I1").Value >= Range("AE" & ThatRow).Value Then
Range("AF" & ThatRow).Formula = MValue
End If
If Range("J1").Value >= Range("AE" & ThatRow).Value Then
Range("AG" & ThatRow).Formula = MValue
End If
If Range("K1").Value >= Range("AE" & ThatRow).Value Then
Range("AH" & ThatRow).Formula = MValue
End If
If Range("L1").Value >= Range("AE" & ThatRow).Value Then
Range("AI" & ThatRow).Formula = MValue
End If
If Range("M1").Value >= Range("AE" & ThatRow).Value Then
Range("AJ" & ThatRow).Formula = MValue
End If
If Range("N1").Value >= Range("AE" & ThatRow).Value Then
Range("AK" & ThatRow).Formula = MValue
End If
If Range("O1").Value >= Range("AE" & ThatRow).Value Then
Range("AL" & ThatRow).Formula = MValue
End If
If Range("P1").Value >= Range("AE" & ThatRow).Value Then
Range("AM" & ThatRow).Formula = MValue
End If
If Range("Q1").Value >= Range("AE" & ThatRow).Value Then
Range("AN" & ThatRow).Formula = MValue
End If
If Range("R1").Value >= Range("AE" & ThatRow).Value Then
Range("AO" & ThatRow).Formula = MValue
End If
If Range("S1").Value >= Range("AE" & ThatRow).Value Then
Range("AP" & ThatRow).Formula = MValue
End If
If Range("T1").Value >= Range("AE" & ThatRow).Value Then
Range("AQ" & ThatRow).Formula = MValue
End If
ElseIf Range("AD" & ThatRow) = False Then
Range("AF" & ThatRow).Value = ""
Range("AG" & ThatRow).Value = ""
Range("AH" & ThatRow).Value = ""
Range("AI" & ThatRow).Value = ""
Range("AJ" & ThatRow).Value = ""
Range("AK" & ThatRow).Value = ""
Range("AL" & ThatRow).Value = ""
Range("AM" & ThatRow).Value = ""
Range("AN" & ThatRow).Value = ""
Range("AO" & ThatRow).Value = ""
Range("AP" & ThatRow).Value = ""
Range("AQ" & ThatRow).Value = ""
End If
End If
End Sub