Excel VBA: The Magic of the Worksheet Change Event

  Рет қаралды 75,765

Excel Macro Mastery

Excel Macro Mastery

Күн бұрын

Пікірлер: 118
@Excelmacromastery
@Excelmacromastery 5 жыл бұрын
Hi everyone, Enjoy your watching and please leave your comments below. Don't forget to press SUBSCRIBE to my channel for more videos. Thanks for your support.
@jorti10191
@jorti10191 4 жыл бұрын
is there a reason why when executing code from a module it randomly will jump to worksheet change event even if worksheet change event sub ended?
@dunuth
@dunuth 4 жыл бұрын
(newb) Is there a reason why I can't use If Target = Range("B2") Then instead of If Application.Intersect... Goto done: ?
@twinkle547
@twinkle547 2 жыл бұрын
Hi can we lock the entire worksheets without protecting using VBA code
@snakeeyesOFFICIAL76
@snakeeyesOFFICIAL76 Жыл бұрын
This is the best content for VBA on youtube
@gregbernard7861
@gregbernard7861 2 жыл бұрын
Awesome. I may have said this before but I’ll say it again - this is the #1 primo VBA code site!
@nathanbowers1761
@nathanbowers1761 3 ай бұрын
Nice work, Paul! Very timely; I was just recently dealing with needing this functionality.
@joelabacherli1310
@joelabacherli1310 10 ай бұрын
Brilliant. The possibilities are endless once a firm grasp is attained and this content is ideal for that. Thank you so much for this information.
@alechill3286
@alechill3286 4 жыл бұрын
You're out here making a positive impact on more lives than you know. Thank you sir!
@Excelmacromastery
@Excelmacromastery 4 жыл бұрын
My pleasure!
@mswordexpert
@mswordexpert 2 жыл бұрын
Thanks a lot, I think that in this particular scenario we can use (Target) in stead of (intersect) if target = Range(B2) then ' run the code
@SalahEddineH
@SalahEddineH 5 жыл бұрын
Your channel is a mine of usefulness! Cheers! Stay awesome!
@Excelmacromastery
@Excelmacromastery 5 жыл бұрын
Thanks for your support Salah.
@JoseVicenteMontes
@JoseVicenteMontes 4 жыл бұрын
Thanks a lot. Very interesting topic with many pitfalls.
@realhuahin
@realhuahin 5 жыл бұрын
I never knew it was possible to use the application dot in the immediate window thanks!
@Chris_Rock
@Chris_Rock 5 жыл бұрын
Love your videos. You always seem to teach me something I've wanted to know, but wasn't sure exactly how to ask when I do an internet search.
@Excelmacromastery
@Excelmacromastery 5 жыл бұрын
glad to help Chris.
@victorpiva701
@victorpiva701 3 жыл бұрын
i cant undertand why u dont have more then 1 M subs. AWESOME videos!
@Excelmacromastery
@Excelmacromastery 3 жыл бұрын
Thanks. Glad you like it.
@dgjanes917
@dgjanes917 5 жыл бұрын
Great video! Could have used it earlier today. Took me a bit to remember the enable events. Cheers!!
@wayneedmondson1065
@wayneedmondson1065 3 жыл бұрын
Great tips! Thanks Paul :)) Thumbs up!!
@jakeabivaofficial
@jakeabivaofficial 4 жыл бұрын
Thanks! Very helpful tutorial.
@NielsHeusinkveld
@NielsHeusinkveld 11 ай бұрын
For years I've used this (which I stole from the internet) and it behaves very well: If Not Intersect(target, Range("B1:B10")) Is Nothing Then end if Running the code every time you change something in the range b1:b10.
@federico.gorrini
@federico.gorrini 3 жыл бұрын
This is really cool man, thanks!
@nelsonrioux5555
@nelsonrioux5555 5 жыл бұрын
Great. Thank you Paul for letting me discover a totally unknown functionality of Excel VBA.
@Excelmacromastery
@Excelmacromastery 5 жыл бұрын
You're welcome Nelson.
@TechTinkTronics
@TechTinkTronics 4 жыл бұрын
Yes! I love the Worksheet Change Events. I have made some very interesting worksheets with code based upon Worksheet Change Events. I love the part about the importance of Application.Enable Events, that has saved me many times. Thanks for making this awesome video!
@richrobins5711
@richrobins5711 5 жыл бұрын
Thanks again! I had used this before but just cut and pasted from an example. Its nice to know how it really works! I added turning off the Events to my code to make sure I did not get into a loop! Great lesson!
@Excelmacromastery
@Excelmacromastery 5 жыл бұрын
Thanks Rich
@sircorn4248
@sircorn4248 3 жыл бұрын
Excellent and very useful video. Thank you
@stevereed5776
@stevereed5776 11 ай бұрын
Thanks Paul. I have a routine that creates a new sheet and fills it in. Is there a way to run an event on the new sheet without having to put the change event code into the new sheet?
@sasavienne
@sasavienne 5 жыл бұрын
Excellent as usual. Thanks Paul.
@Excelmacromastery
@Excelmacromastery 5 жыл бұрын
Thanks K D
@wiktorkabanow
@wiktorkabanow 4 жыл бұрын
fantastic explanation of events! learned stuff
@bawlsackinharry5855
@bawlsackinharry5855 5 жыл бұрын
I love your videos. Thanks so much for taking the time to put these together!
@Excelmacromastery
@Excelmacromastery 5 жыл бұрын
Thanks Bawlsackin.
@joaocustodio2094
@joaocustodio2094 5 жыл бұрын
Another very useful and didactic video. Thanks Paul.
@Excelmacromastery
@Excelmacromastery 5 жыл бұрын
You're welcome. Thanks Joao.
@JonathanExcels
@JonathanExcels 5 жыл бұрын
Do you have a video about the call stack? This was the first time I’ve seen that window used.
@Excelmacromastery
@Excelmacromastery 5 жыл бұрын
Hi Jonathan. I might do a video on it in the future. There is not a lot to it but I think many people are not familiar with it.
@edwinmiranda4005
@edwinmiranda4005 5 жыл бұрын
First time I heard of call stack too, and I’ve been working with VBA for 2 years now
@cavokrider
@cavokrider 11 ай бұрын
Really excellent!!!!
@the_feature_selector859
@the_feature_selector859 5 жыл бұрын
Great video again. Also the addition of using Call Stack... Never knew that existed. Really useful in debugging!
@VIPULDJHAVERI
@VIPULDJHAVERI 3 жыл бұрын
brillinat and very precise , as usual in all your videos thanks for sharing mastery Mr. Paul at 8.13 when we deleted cells in col B target cell made blank but color remains , pl inform how we improve to take care for such change in target cell even in multiple range selected
@wpryan02358
@wpryan02358 Жыл бұрын
Thanks for your helpful and informative videos. I became an instant fan! In the case of the Worksheet Change event, I have been using the command "if target.address = ("cell reference here") then...". Is there an advantage to one or the other...?
@walterbierkens
@walterbierkens 4 жыл бұрын
Great video's! I wonder why to use "Application.Intersect", while we can use the simpler: "if Target = Activesheet.Range("B2")"? Because the latter one also works!
@kiwim3p587
@kiwim3p587 Жыл бұрын
I was wondering about this also
@edge5817
@edge5817 5 жыл бұрын
thank you Paul... I learned something new again!
@PrincePedia
@PrincePedia 5 жыл бұрын
Great video! Thanks Paul.
@Excelmacromastery
@Excelmacromastery 5 жыл бұрын
Thanks Prince.
@stevennye5075
@stevennye5075 5 жыл бұрын
Good explanation!
@montmraaa
@montmraaa 3 жыл бұрын
I normally loop through the cells in Target to evaluate each individually. This will work when multiple cells are changed as part of the same event.
@S_g88
@S_g88 Жыл бұрын
Hey... Thank you sooo much bro... 😊
@mdismailhosen8280
@mdismailhosen8280 4 жыл бұрын
is it possible to triger worksheet change event to act like combobox change event?
@oguzturkyilmaz543
@oguzturkyilmaz543 3 жыл бұрын
Thank you very much
@michaelallen7613
@michaelallen7613 Жыл бұрын
Great video. You have a new subscriber. Do you have anything similar for comboboxes. They are really troubleshooting for me.
@josephdaquila2479
@josephdaquila2479 Жыл бұрын
To get an understanding of when various Excel events run I like to just write a line of msgbox code to say whatever event just ran.
@KarthikKAVE
@KarthikKAVE 4 жыл бұрын
Again proved you are master in VBA code. May I know how many years experience in VBA coding?
@lennysaucier
@lennysaucier 3 ай бұрын
Like it. In particular, when the value is changed, I am trying to return the old value of b31 to b33. I cannot figure it out. Can you help
@ventjemazzel8822
@ventjemazzel8822 5 жыл бұрын
Thank you again for another great video Paul; I have a question:how about using an IF statement like this: If target.Address="B2" Then run the code?
@Excelmacromastery
@Excelmacromastery 5 жыл бұрын
That's fine when only one cell is returned but if multiple cells are returned they it won't work.
@iincitr
@iincitr 5 жыл бұрын
Thank you again Paul.
@Excelmacromastery
@Excelmacromastery 5 жыл бұрын
Thank you too Ismail
@MohAboAbdo
@MohAboAbdo 4 жыл бұрын
Thank You So Mutch, Sir.
@peter00000001
@peter00000001 3 жыл бұрын
Nice, very good for the first steps, but I trying to understand the custom events for dynamically created objects on a form. But the interaction between the different classes is not clear for me. And on the internet I find not really a good explanation or example that give me the full insights. Is this something that will come in an future video?
@WTC_2U
@WTC_2U 5 жыл бұрын
Thanks Paul. your example shows just a single character being changed, triggering the event. What happens if we type a multi-character word/phrase - does the event trigger with each new character entered? If I type in "Paul", does the Change event trigger once, or four times?
@Excelmacromastery
@Excelmacromastery 5 жыл бұрын
It only triggers when the you finish entering data in a cell.
@WTC_2U
@WTC_2U 5 жыл бұрын
Excel Macro Mastery - thank you!
@muriwangul.chinyerere5381
@muriwangul.chinyerere5381 4 жыл бұрын
Great video👏👏👏
@Excelmacromastery
@Excelmacromastery 4 жыл бұрын
Thank you 👍
@krn14242
@krn14242 5 жыл бұрын
Thanks Paul, I use this with drop down data validations alot. I like the idea about the GoTo though.
@Excelmacromastery
@Excelmacromastery 5 жыл бұрын
Thanks for always leaving your comments for my videos.
@amarnadhg6896
@amarnadhg6896 5 жыл бұрын
Long awaited for this, Thanks for post, keep doing videos on Events
@Excelmacromastery
@Excelmacromastery 5 жыл бұрын
Glad you liked it.
@niharikagaikwad2865
@niharikagaikwad2865 3 жыл бұрын
Hi Kenny! This video worked wonders for me. Thanks a lot! Also, what can I do if I have to run the same code in the same sheet for different blocks of cells when different letters are typed in? For eg: If I type D, another block of cell should get colored
@tonyhaddad1088
@tonyhaddad1088 4 жыл бұрын
Thank you for your wonderful lessons Is there a way to make a column accepts only numeric values? Or perhaps date
@trevorburford-reade8685
@trevorburford-reade8685 4 жыл бұрын
Use Data Validation.
@iidseans5442
@iidseans5442 2 жыл бұрын
Thanks for the content. Now I'm trying to imagine how I can combine this with a timer. I want to use a WS.Active event to run a macro(Manual Calculate this sheet). But other macros are already in/activating the WS to un/protect all sheets as part of the open/close WB process. All I can think is to activate the WS and invoke a timer to run a macro to toggle WS.Calculate on and off. Anyone have a good idea?
@UncleChopChop22
@UncleChopChop22 5 жыл бұрын
Just got a notification for your latest video but won't let me watch as it says it's private?
@dandeman1148
@dandeman1148 5 жыл бұрын
Nice, but how can you use The event to copy and delete a row another sheet If an item in column 2 is a certain text
@johnjoecawleyie6004
@johnjoecawleyie6004 Жыл бұрын
Any Chance of you giving the code for this Paul. I have not managed to duplicate it myself.
@TheUnicleo
@TheUnicleo 4 жыл бұрын
does Target.Address="$B$2" serve better than Intersect(..)?
@jankichanddevi6538
@jankichanddevi6538 4 жыл бұрын
Hi, I learnt vba but I am not able to start any automation in my office. Would you please give me some tips to perfect in vba automation. Please advise.
@ezequiasrocha3037
@ezequiasrocha3037 5 ай бұрын
Worksheet change event does not track the moment when I change the sheet name. 😔 By the way, why does Excel doesn't track the sheet renaming event?
@kanbalan3043
@kanbalan3043 4 жыл бұрын
Hey this is fantastic I could create a data entry form where user will be able to check data entry error soon they finished entering the last digit fab I wonder you could solve this problem for me . here we are ... I created a data entry form and linked the database below so that user can select a particular row and then edit or delete so far so good The issue is I want to make this list to be in descending order and as and when a new row of data is entered this appear right at the top so that the user know what is the last piece of data entered
@sapisoftware1942
@sapisoftware1942 5 жыл бұрын
Hi Paul, awesome your videos! Could you to consider a couple videos of how to use MSXML2.XMLHTTP60 library to do webscraping? Especially querySelector instead of Xpath (it seems does not exists for this library). Regards!!
@meldeebueno
@meldeebueno 5 жыл бұрын
I have been using worksheet change for years. One problem I was having is that when I put formula on my target cell so that when that value changes, the cell that would reflect the resulting event should change too depending the value I set. However, it's not working like that because Excel is only proceeding with worksheet change when the cell value has changed and not merely the resulting value from a value (which Excel reads as non-modification).
@meldeebueno
@meldeebueno 5 жыл бұрын
Could have a lot of practical applications only if Excel reads values changes from formulas as modification but I get it.
@meldeebueno
@meldeebueno 5 жыл бұрын
@Carsten Mikkelsen Thank you, Carsten. Appreciate the help. This will help me a lot in doing my reports moving forward. Thank you for taking a chunk of your time for a clarification.
@anandchhangani1031
@anandchhangani1031 4 жыл бұрын
Thanks dear. Excellent video on VBA worksheet change event. I have been using it for a long time, but never exactly knew as to when I should enable or disable the events and that your video has cleared my confusions in this regard. Recently I am trying to save live streaming data of stock prices (already subscribed by me and which are streaming in my sheet1). The data actually appears and then next moment new data comes. The streaming data are coming in Range("A1:M1") and I want to capture and save and then analyze those data. For saving data I tried to use Worksheet Change event but it is not working and I don't know why it is not working. The worksheet change event has been coded as follows: Private Sub Worksheet_Change(ByVal Target As Range) Dim i As Integer Application.ScreenUpdating = False If Application.Intersect(Target, ActiveSheet.Range("A3:M3").Value) Is Nothing Then GoTo done Application.EnableEvents = False i = Sheet2.Range("A" & Rows.Count).End(xlUp).Row + 1 Range("A3:M3").Copy Sheet2.Range("A" & i) Application.CutCopyMode = False Application.ScreenUpdating = True Application.EnableEvents = True done: Exit Sub End Sub The code stops on line "If Application.Intersect showing run time error 424 (Object Required)........" About Target.Address the watch window says: "Out of Context". Any help....please point out the mistake...
@christianbaert607
@christianbaert607 5 жыл бұрын
Very useful vid ... as usual :-) Although, I am a bit puzzled with the Intersect command. Why not using "If Target.Address = "B2" then ... It seems easier to me. Or did I miss something ?
@michael.andreae
@michael.andreae 5 жыл бұрын
I guess this would work as long as only one cell is returned, but if you change more than one cell you get an Array back. Intersect is a clever way of handeling both cases.
@christianbaert607
@christianbaert607 5 жыл бұрын
@@michael.andreae Thanks a lot Michael ! You are right, of course. I should try that next time I need it.
@Excelmacromastery
@Excelmacromastery 5 жыл бұрын
Exactly what Michael said😀
@ottoleisering7855
@ottoleisering7855 5 жыл бұрын
Why put "exit sub" after the "done: label when the very next line is "end sub"?
@Excelmacromastery
@Excelmacromastery 5 жыл бұрын
Because you would normally add the error handling section after the exit sub.
@alteavanloggerenberg2464
@alteavanloggerenberg2464 Жыл бұрын
Hi, what if you had 11 sheets but you only wanted 7 specific sheets to trigger the event change, how would you go about it?
@david_allen1
@david_allen1 Жыл бұрын
There is a Workbook_SheetChange event that runs after every Worksheet_Change event (there is one for each sheet) for every sheet in the workbook. You would have to put code in the Workbook_SheetChange event that checks for the name (or number) of the sheet which had a change (for example using Target.Parent.Name or the Sh.Name parameter specified in the event definition), and when the sheet matches one that you want to catch, execute your intended code; otherwise, just exit the sub. You could perform the check easily with a SELECT CASE construct or an IF/ELSEIF construct.
@thearchibaldtuttle
@thearchibaldtuttle 5 жыл бұрын
For the purpose of demonstration I forgive you the GOTO!
@edwinmiranda4005
@edwinmiranda4005 5 жыл бұрын
Is there another way to handle that with out GoTo?
@thearchibaldtuttle
@thearchibaldtuttle 5 жыл бұрын
5.SL0 Like this: If Not Intersect(....) Is Nothing Then Do something End If
@edwinmiranda4005
@edwinmiranda4005 5 жыл бұрын
Archibald Tuttle ok cool
@Excelmacromastery
@Excelmacromastery 5 жыл бұрын
I actually don't like this method because if you have multiple if then you end up with multiple levels of indentation. It makes the code difficult to read. doing an exit/goto upon failure makes the code flow more obvious. Of course it's down to a personal choice.
@CANDEEIRO
@CANDEEIRO 7 ай бұрын
well... you can use conditional formatting instead. It's so simple... :D
@naveenofficial3680
@naveenofficial3680 4 жыл бұрын
What if target cell is set by another cell reference?? It is not working. I hv a sheet in which value of a cell is pasted by another cell every time. What can be done? Plzz guide me
@Caracazz2
@Caracazz2 3 жыл бұрын
Doesn't work with web query or any automatic cell change. Only works when user changes it manually.
@wren4077
@wren4077 3 жыл бұрын
Why does my target say "target = nothing " when highlighted
@raypang8400
@raypang8400 2 жыл бұрын
dude not even following on the watch step, my file just keep giving me out of context in value for target address and empty in type and sometimes just dont respond at all
@deechvogt1589
@deechvogt1589 3 жыл бұрын
I really like your videos but this time I do have an issue with the introduction of using the GoTo statement when you could have easily written the code to just drop through to the end sub. The done label and the Exit Sub statements were completely unnecessary.
@ghoulsarefree
@ghoulsarefree 4 жыл бұрын
You should add music to your videos.
@ImAHugeTroll
@ImAHugeTroll 5 жыл бұрын
The reason i hesitate to use workbook change events is because as far as i know there is no way to undo your actions because you are triggering macros at every change. otherwise i think this would be a much more useful workbook event because so often i want to use it but cant justify it
@Excelmacromastery
@Excelmacromastery 5 жыл бұрын
That's true. You have to be careful with it.
@tughanozsezer9332
@tughanozsezer9332 5 жыл бұрын
👍
@user_2085
@user_2085 2 жыл бұрын
This is not magic
@mike_case
@mike_case 5 жыл бұрын
Thank you Paul!!! Once again great content.
@Excelmacromastery
@Excelmacromastery 5 жыл бұрын
Thanks Michal
How to make your Excel VBA code run 1000 times faster
16:55
Excel Macro Mastery
Рет қаралды 365 М.
Excel VBA: The Little-known secrets of ByVal and ByRef
13:00
Excel Macro Mastery
Рет қаралды 47 М.
UFC 310 : Рахмонов VS Мачадо Гэрри
05:00
Setanta Sports UFC
Рет қаралды 1,2 МЛН
It’s all not real
00:15
V.A. show / Магика
Рет қаралды 20 МЛН
Beat Ronaldo, Win $1,000,000
22:45
MrBeast
Рет қаралды 158 МЛН
Reduce VBA Errors by 90% (with this little-known Method)
16:59
Excel Macro Mastery
Рет қаралды 59 М.
I Built a Modern Listbox UI for Excel VBA
14:13
Excel Macro Mastery
Рет қаралды 12 М.
Python in Excel vs. VBA - What You Should Learn in 2024!
10:05
David Langer
Рет қаралды 77 М.
5 Excel Secrets You'll Be Embarrassed You Didn't Know
17:32
Excel Campus - Jon
Рет қаралды 285 М.
If __name__ == "__main__" for Python Developers
8:47
Python Simplified
Рет қаралды 420 М.
How to get the Last Row in VBA(The Right Way!)
15:41
Excel Macro Mastery
Рет қаралды 169 М.
How to Use Class Interfaces in Excel VBA
20:16
Excel Macro Mastery
Рет қаралды 83 М.
The 7 Keys Areas of Excel VBA (with code examples)
28:00
Excel Macro Mastery
Рет қаралды 66 М.
I built my own 16-Bit CPU in Excel
15:45
Inkbox
Рет қаралды 1,7 МЛН
UFC 310 : Рахмонов VS Мачадо Гэрри
05:00
Setanta Sports UFC
Рет қаралды 1,2 МЛН