Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
It means that a variable named Target is passed in to the
procedure. The Target variable is a Range type variable, meaning that it refers to (points to) a cell or range of cells. -- Cordially, Chip Pearson Microsoft MVP - Excel Pearson Software Consulting, LLC www.cpearson.com "Zygoid " wrote in message ... what does (ByVal Target As Range) mean? --- Message posted from http://www.ExcelForum.com/ |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Thanks for your reply. I am new and learning.
How could I change this target to a range of A1:A50 rather than just the single cell? Private Sub Worksheet_Change(ByVal Target As Range) With Target(1) If .Address = "A1" Then If .Value < "" Then --- Message posted from http://www.ExcelForum.com/ |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Zygoid,
Perhaps this will help. The first test looks to see if the changed selection is completely within the range A1:A50. The second checks to see whether the changed selection intersects the range at all: Private Sub Worksheet_Change(ByVal Target As Range) If Union(Target, Range("A1:A50")).Address = "$A$1:$A$50" Then MsgBox "target is completely within A1:A50" ElseIf Not Intersect(Target, Range("A1:A50")) Is Nothing Then MsgBox "target intersects A1:A50" Else MsgBox "target and A1:A50 don't intersect" End If End Sub hth, Doug "Zygoid " wrote in message ... Thanks for your reply. I am new and learning. How could I change this target to a range of A1:A50 rather than just the single cell? Private Sub Worksheet_Change(ByVal Target As Range) With Target(1) If .Address = "A1" Then If .Value < "" Then --- Message posted from http://www.ExcelForum.com/ |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Thanks again for a reply! someone had given a suggestion to change the
code to this With Target(1) If Union(Target, Range("A1:A50")).Address = "$A$1:$A$50" Then If .Value < "" Then Application.ScreenUpdating = False Set SourceWB = Workbooks.Open("path\to\workbook") ActiveWorkbook.Sheets("1").Activate If Sheets("1").Range("A1:A50").Find( _ What:=.Value) Is Nothing Then SourceWB.Close True FORM.Show 'rename form to fit End If End If End If End With This works great to open the form if text in cell is not listed, but I have discovered another problem.. if the text in the cell is listed, the sourceWB will not close. it stays open and is activated. i figured i would need to add something like If Sheets("1").Range("A1:A50").Find( _ What:=.Value) Is Something Then SourceWB.Close True end if I have tried many variations by changing the word "nothing" but it doesn't work. Any suggestions? --- Message posted from http://www.ExcelForum.com/ |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
One way:
Dim found As Range With Target(1) If Not Intersect(.Cells, Range("A1:A50")) Is Nothing Then If Not IsEmpty(.Value) Then Application.ScreenUpdating = False With Workbooks.Open(pathtoworkbook) Set found = .Sheets("1").Cells.Find( _ What:=Target(1).Value) .Close True End With If found Is Nothing Then _ FORM.Show 'rename form to fit End If End If End With In article , Zygoid wrote: Thanks again for a reply! someone had given a suggestion to change the code to this With Target(1) If Union(Target, Range("A1:A50")).Address = "$A$1:$A$50" Then If .Value < "" Then Application.ScreenUpdating = False Set SourceWB = Workbooks.Open("path\to\workbook") ActiveWorkbook.Sheets("1").Activate If Sheets("1").Range("A1:A50").Find( _ What:=.Value) Is Nothing Then SourceWB.Close True FORM.Show 'rename form to fit End If End If End If End With This works great to open the form if text in cell is not listed, but I have discovered another problem.. if the text in the cell is listed, the sourceWB will not close. it stays open and is activated. i figured i would need to add something like If Sheets("1").Range("A1:A50").Find( _ What:=.Value) Is Something Then SourceWB.Close True end if I have tried many variations by changing the word "nothing" but it doesn't work. Any suggestions? --- Message posted from http://www.ExcelForum.com/ |
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
thanks! works great. i have spent hours pulling my hair out trying t
figure this out. :- -- Message posted from http://www.ExcelForum.com |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
REPSOT?? Sub Worksheet_Change(ByVal Target As Range) | Excel Discussion (Misc queries) | |||
Multiple values in Private Sub Worksheet_Change(ByVal Target As R | Excel Discussion (Misc queries) | |||
ByVal Target Range Great Code but need Help | Excel Discussion (Misc queries) | |||
Private Sub Worksheet_Change(ByVal Target As Excel.Range) | Excel Worksheet Functions | |||
Many Sub Worksheet_Change(ByVal Target As Range) In One Worksheet | Excel Programming |