Change cell value based on another cell when checkbox is checked

Rocksie

New Member
Joined
May 17, 2017
Messages
26
Hi

I was wondering if someone could help?

I have 2 checkboxes which cannot be selected at the same time. When one checkbox is selected, an entire row is hidden if the cell in column A ="X". Now I also need to change the value in column F to "N/A" in the row that is being hidden.

What would the VBA code looks like?

Thanks
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Rocksie, The code below will hide all Rows if there is an "X" in Column A and it also places "N/A" in Column F of that same Row.
I assumed that you have a Header Row in Row 1 so the code starts checking in Row 2.
Code:
Sub FilterX()
Dim LastRow As Long
Dim i As Long


LastRow = Cells(Rows.Count, "A").End(xlUp).Row
For i = 2 To LastRow
    If Cells(i, 1) = "X" Then
        Rows(i).EntireRow.Hidden = True
        Cells(i, 6).Value = "N/A"
    End If  '  Cells(i, 1) = "x"
Next i


End Sub
 
Last edited:
Upvote 0
Thank you frank_AL for the code.

I have the following code and just want to change the values of the hidden rows in column "F" to be "N/A"

Private Sub CheckBox2_Change()

If CheckBox2 = True Then
lr = Range("A" & Rows.Count).End(xlUp).Row
Set cl_rng = Range("A30:A" & lr)

For Each cl In cl_rng
If cl.Value = "X" Then cl.EntireRow.Hidden = True
Next cl

Else
Cells.Select
Selection.EntireRow.Hidden = False
End If

ActiveSheet.Range("I33").Select

End Sub
 
Upvote 0
Rocksie, See change below that will change the values of the hidden rows in column "F" to be "N/A"

Code:
Dim cr as Long
[/COLOR][COLOR=#333333]For Each cl In cl_rng[/COLOR]
[COLOR=#333333]    If cl.Value = "X" Then cl.EntireRow.Hidden = True
[/COLOR]    If c.EntireRow.Hidden Then
        cr = cl.Row
        [COLOR=#333333]Cells(cr, 6).Value = "N/A"
    End If[/COLOR]
[COLOR=#333333]Next cl[/COLOR][COLOR=#333333]
 
Upvote 0

Forum statistics

Threads
1,223,952
Messages
6,175,596
Members
452,657
Latest member
giadungthienduyen

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