Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default what does (ByVal Target As Range) mean

what does (ByVal Target As Range) mean

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default what does (ByVal Target As Range) mean

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default what does (ByVal Target As Range) mean

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 770
Default what does (ByVal Target As Range) mean

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default what does (ByVal Target As Range) mean

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 40
Default what does (ByVal Target As Range) mean

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default what does (ByVal Target As Range) mean

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
REPSOT?? Sub Worksheet_Change(ByVal Target As Range) Ed Davis[_2_] Excel Discussion (Misc queries) 14 October 13th 09 03:20 PM
Multiple values in Private Sub Worksheet_Change(ByVal Target As R davemon Excel Discussion (Misc queries) 2 September 21st 07 07:40 PM
ByVal Target Range Great Code but need Help Mark Excel Discussion (Misc queries) 31 July 27th 07 03:11 PM
Private Sub Worksheet_Change(ByVal Target As Excel.Range) [email protected] Excel Worksheet Functions 0 December 21st 06 02:13 AM
Many Sub Worksheet_Change(ByVal Target As Range) In One Worksheet MathewPBennett Excel Programming 4 December 24th 03 01:01 PM


All times are GMT +1. The time now is 11:13 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"