Explanation of code
Hi, I am pretty new to vb and I was wondering if somebody could explai me how this code works: Private Sub Worksheet_Change(ByVal Target As Range) Dim temp As Range Set temp = Intersect(Target, Range("H3:H16")) If temp Is Nothing Then Else Target.Offset(0, -1) = Target.Offset(0, -1) - Target End If End Sub what does 'Target As Range' mean and how can 'Target' be something i we dont input anything? Also explain the intersect function please. Thanks a lot guys. Regards, Marco ----------------------------------------------- ~~ Message posted from http://www.ExcelTip.com ~~View and post usenet messages directly from http://www.ExcelForum.com |
Explanation of code
Hi Marcos
The WorksheetChange is a predefined event, the macro runs when cells are changed. We don't input anything, Excel does herself. She inputs Target, which is the cell or the cells that just changed content. A range is one or more cells. Target is a range, H3:H16 is another. Intersect is the cells that those two ranges have in common. If you change (for example by Paste) the cells C4:N4 then this is Target and cell H4 is the cell that is exist both ranges, it's "intersect". If Intersect is nothing then Target has nothing to do with H3:H16, otherwise an action is performed. -- HTH. Best wishes Harald Followup to newsgroup only please "marksuza" skrev i melding ... Hi, I am pretty new to vb and I was wondering if somebody could explain me how this code works: Private Sub Worksheet_Change(ByVal Target As Range) Dim temp As Range Set temp = Intersect(Target, Range("H3:H16")) If temp Is Nothing Then Else Target.Offset(0, -1) = Target.Offset(0, -1) - Target End If End Sub what does 'Target As Range' mean and how can 'Target' be something if we dont input anything? Also explain the intersect function please. Thanks a lot guys. Regards, Marcos ------------------------------------------------ ~~ Message posted from http://www.ExcelTip.com/ ~~View and post usenet messages directly from http://www.ExcelForum.com/ |
Explanation of code
Thanks for the help ----------------------------------------------- ~~ Message posted from http://www.ExcelTip.com ~~View and post usenet messages directly from http://www.ExcelForum.com |
All times are GMT +1. The time now is 11:38 AM. |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com