Two worksheet event changes in a single VBA code.

Status
Not open for further replies.

Livin404

Active Member
Joined
Jan 7, 2019
Messages
460
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Greetings, I've tried to combine two worksheet event changes to a single VBA. I think I'm on the right path, I combined the two by adding another Application.EnablEvents. It works fine until I delete any row or cells then it doesn't work. Any suggestions, I'm sure it's just a little tweak?


VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
Columns.Autofit
If Target.Cells.Count > 1 Then Exit Sub
If Taret.Column <> 6 Then Exit Sub
Application.EnableEvents = False
Cells(Target.Row, "G").Value = UCase(Split(Application.UserName, ",")(0))
Application.EnableEvents = True
End Sub



Thank you,
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"

StephenCrump

MrExcel MVP
Joined
Sep 18, 2013
Messages
4,245
Office Version
  1. 365
Platform
  1. Windows
It's not very helpful to say "doesn't work". What is actually happening? Or not happening?

A quick look suggests two possible problems:

1. You have a typo: Taret.Column (although I suspect your code is OK, and you've just miscopied it?)

2. You also need to remove the first: Application.EnableEvents = False

If the code exits the Sub at lines 4 or 5, the Sub won't be triggered by subsequent worksheet changes.

You may also need to reset Application.EnableEvents = True.
 
Status
Not open for further replies.

Forum statistics

Threads
1,141,309
Messages
5,705,675
Members
421,404
Latest member
Mikecollo

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
Top