Two VBA macros - one appears to not work once a change is made

caet_

New Member
Joined
Nov 22, 2020
Messages
28
Office Version
  1. 2016
Platform
  1. Windows
Hello all,
I hope to find you well.

I'm having a problem with a macro that I'm using in a excel questionnaire. Everything works ok when I follow the "correct" order of filling the questionnaire.

However, when I change the cell D10 after selecting the option YES or NO in H20, the Check Box 5 and Check Box 6 appear again (even when the "NO is selected").

For example: I have insered a code, then I have selected "NO" and then I have change the code to 300. As you can see, the checkboxes appeared again. If I select "NO" again, the checkboxes disappear again.

1606074422753.png

Does anyone know how can I solve this issue?

I have attached the workbook.

Example.xlsm
ABCDEFGHIJKLMNOPQRSTUVWXYZAAABACADAEAFAGAHAIAJAK
1100
2200
3300YES
4400NO
5500
6600
7700
8
9
10Code700
13DirectFALSE0
14IndirectFALSE0
20DisccountNO
23Last order Date:
24VAT:
25Fraction:
26
27
28
29
30Products
31A
32B
33C
34D
35
Sheet1
Cell Formulas
RangeFormula
AJ13:AJ14AJ13=+IF(AI13=TRUE,1,0)
Cells with Data Validation
CellAllowCriteria
D10List=$V$1:$V$7
H20List=$W$3:$W$4


Thank you a lot!
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Here you can find the VBA Codes

Module 1:

VBA Code:
Option Explicit

 

Sub Checkbox1()

If Sheet1.[D10] = 100 Or Sheet1.[D10] = 200 Then

    With ActiveSheet

        .CheckBoxes("CheckBox2").Visible = False

        .Rows("32").EntireRow.Hidden = True

        .Rows("31").EntireRow.Hidden = False

        .Rows("33:34").EntireRow.Hidden = False

    End With

ElseIf Sheet1.[D10] = 300 Or Sheet1.[D10] = 400 Then

    With ActiveSheet

        .CheckBoxes("CheckBox3").Visible = False

        .CheckBoxes("CheckBox4").Visible = False

        .CheckBoxes("CheckBox1").Visible = True

        .CheckBoxes("CheckBox2").Visible = True

        .Rows("33:34").EntireRow.Hidden = True

        .Rows("31:32").EntireRow.Hidden = False

    End With

ElseIf Sheet1.[D10] = 500 Or Sheet1.[D10] = 600 Or Sheet1.[D10] = 700 Then

    With ActiveSheet

        .Rows("29:32").EntireRow.Hidden = False

    End With

    End If

 

 

End Sub

 

 

Sub Unhide()

Dim chk As Checkbox

For Each chk In ActiveSheet.CheckBoxes

    chk.Visible = True

Next

End Sub

 

Sub Disccount()

If Sheet1.[H20] = "NO" Then

With ActiveSheet

.CheckBoxes("Check Box 5").Visible = False

.CheckBoxes("Check Box 6").Visible = False

.Rows("21:22").EntireRow.Hidden = True

End With

ElseIf Sheet1.[H20] = "YES" Then

    With ActiveSheet

.CheckBoxes("Check Box 5").Visible = True

.CheckBoxes("Check Box 6").Visible = True

.Rows("21:22").EntireRow.Hidden = False

  End With

    End If

End Sub


Sheet 1:

VBA Code:
Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)

    Call Macro1(Target)

    Call Macro2(Target)

End Sub

 

Sub Macro1(ByVal Target As Range)

    If Target.Cells.Count > 1 Then Exit Sub

    If Not Intersect(Target, Range("D10")) Is Nothing Then

        Checkbox1

        Unhide

    End If

End Sub

 

 

Sub Macro2(ByVal Target As Range)

    If Target.Cells.Count > 1 Then Exit Sub

    If Not Intersect(Target, Range("H20")) Is Nothing Then

        Disccount

    End If

End Sub
 
Upvote 0

Forum statistics

Threads
1,215,517
Messages
6,125,288
Members
449,218
Latest member
Excel Master

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top