[VBA] How change in each column from YES to NO to change YES or NO respectively in column H in the corresponding row ?

vbalad

New Member
Joined
Feb 3, 2023
Messages
8
Office Version
  1. 365
  2. 2021
  3. 2019
  4. 2016
Platform
  1. Windows
Hi all,

I would like each change in each column from YES to NO to change YES or NO respectively in column H in the corresponding row.
I have this code:

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim MonitoredRange As Range
    Set MonitoredRange = Range("A1:C6")

    If Not Intersect(Target, MonitoredRange) Is Nothing Then
        Dim Cell As Range
        For Each Cell In Intersect(Target, MonitoredRange)
            If Cell.Value = "TAK" Then
                Call ChangeCellValue("TAK", Target.Row)
            ElseIf Cell.Value = "NIE" Then
                Call ChangeCellValue("NIE", Target.Row)
            End If
        Next Cell
    End If
End Sub

Sub ChangeCellValue(NewValue As String, RowToChange As Long)
    Dim ws As Worksheet
    For Each ws In ThisWorkbook.Worksheets
        ws.Cells(RowToChange, "H").Value = NewValue 
    Next ws
End Sub
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
So, how is your code NOT working now?
Can you show us a sample of your data, walk us through an example, and tell us what the code is currently doing, and what it should be doing in that case?
 
Upvote 0
Hi,

Here is example:

test_macro_intersect.xlsm
ABCDEFGH
1NIETAKTAKTAK
2NIETAKNIETAK
3TAKNIETAKTAK
4TAKTAKTAKTAK
5TAKTAKTAKTAK
6NIETAKTAKTAK
Arkusz1
Cells with Data Validation
CellAllowCriteria
H1:H6ListTAK;NIE
A1:C6ListTAK;NIE


When I change something happens nothing

Regards
 
Upvote 0
It works just fine for me.

What is the name of the module you have placed this VBA code in?
It needs to be in the particular Sheet module (all "Worksheet" event procedures need to be in the worksheet module of the sheet you want it to run in).
If it is in any other module, it will NOT work automatically.
 
Upvote 0
Solution
Hi,

Works. You're right, Joe4
I had placed in "This Workbook" instead of in "Sheet1". My English is pretty good, but mistakes happen ;)

Regards
 
Upvote 0

Forum statistics

Threads
1,224,817
Messages
6,181,148
Members
453,021
Latest member
Justyna P

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