Cells not updating with Worksheet_Change(ByVal Target As Excel.Range)

LlebKcir

Board Regular
Joined
Oct 8, 2018
Messages
219
Thank you everyone in advance for the help. I am still learning basic VBA so this one is a bit of a stretch...

For all cells in column A that are updated (be that manually entered, or updated via click and drag, other) I want a specific output in column B. I have the if statements working as desired when data is manually entered into column A, but any other type of manipulation including mass select and delete fail to update column B.

Code:
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
    If Target.Column = 1 Then
        ThisRow = Target.Row


            If Range("a" & ThisRow).Value Like "*foo1*" Or Range("a" & ThisRow).Value Like "*foo2*" Then
                Range("b" & ThisRow).Value = "OUT1"
            Else
                If Range("a" & ThisRow).Value Like "*foo3*" Or Range("a" & ThisRow).Value Like "*foo4*" Or Range("a" & ThisRow).Value Like "*foo5*" Then
                    Range("b" & ThisRow).Value = "OUT2"
            Else
                If Range("a" & ThisRow).Value Like "*foo6*" Or Range("a" & ThisRow).Value Like "*foo7*" Or Range("a" & ThisRow).Value Like "*foo8*" Or Range("a" & ThisRow).Value Like "*f0016*" Then
                    Range("b" & ThisRow).Value = "OUT3"
            Else
                If Range("a" & ThisRow).Value Like "*foo9*" Or Range("a" & ThisRow).Value Like "*foo10*" Or Range("a" & ThisRow).Value Like "*foo11*" Or Range("a" & ThisRow).Value Like "*foo17*" Then
                    Range("b" & ThisRow).Value = "OUT4"
            Else
                If Range("a" & ThisRow).Value Like "*foo12*" Then
                    Range("b" & ThisRow).Value = "OUT5"
            Else
                If Range("a" & ThisRow).Value Like "*foo13*" Or Range("a" & ThisRow).Value Like "*foo14*" Or Range("a" & ThisRow).Value Like "*foo15*" Then
                    Range("b" & ThisRow).Value = "OUT6"
            Else
                If IsEmpty(Range("a" & ThisRow).Value) Then
                    Range("b" & ThisRow).Value = ""
            End If
            End If
            End If
            End If
            End If
            End If
            End If


    End If


End Sub

so rather simple set of code, but what am i missing to enable the click/drag or double click on a cell in column A to update all of the equal number of cells in column B?

Thank you again in advance.
 
roww is just the row number of the cell being looped i.e. rng in the code.

Btw, you don't mark posts as Solved on this forum, you just say thank you which you have already done :)
 
Upvote 0

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
roww is just the row number of the cell being looped i.e. rng in the code.

Btw, you don't mark posts as Solved on this forum, you just say thank you which you have already done :)

Got ya on the cell being looped. That explains why that works. The little digging I found that Excel only marks the initially selected cell as "active" and thus the vba code was failing to update the non-active cells for desired output.

Thank you for the info. It is always a great way to start the day by learning something new.
 
Upvote 0
You're welcome and as you have probably noted by what Fluff posted you rarely need to Select/Activate anything to work with them in VBA.
 
Upvote 0
You're welcome and as you have probably noted by what Fluff posted you rarely need to Select/Activate anything to work with them in VBA.

Sorry I was not clear. The initial code I posted functioned with the following issues:

column B, only populated when column A was manually edited.

ex: manually type any desired filter for the LIKE() function, hit enter and column B would populated desired OUT.
copy/paste the cell from column A down and only 1 cell in column B would populate. The same held true for deleting cells in column A.

The updated code functions no matter how column A is edited.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,331
Members
452,636
Latest member
laura12345

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