ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Range Reference in Visual Basic (https://www.excelbanter.com/excel-programming/283337-range-reference-visual-basic.html)

John Baker

Range Reference in Visual Basic
 
Hi:

I have the following worksheet based macro in VBA:


Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Address = "$F$5" Then
Run "buttonchange"
End If
End Sub

I want to expand the target address to F5 OR F6, and have no idea how to do it. Whatever I
try $F$5:$F$6, $F$5 OR $F$6 or a myriad of variations around that come up with a compile
error OR don't work!

Anyone got any thoughts on this?

Regards
John Baker

Don Guillett[_4_]

Range Reference in Visual Basic
 
simplest would be
If Target.Address = "$F$5" or Target.Address = "$F$6" Then
or
intersect(target,range("f5:f6"))

--
Don Guillett
SalesAid Software

"John Baker" wrote in message
...
Hi:

I have the following worksheet based macro in VBA:


Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Address = "$F$5" Then
Run "buttonchange"
End If
End Sub

I want to expand the target address to F5 OR F6, and have no idea how to

do it. Whatever I
try $F$5:$F$6, $F$5 OR $F$6 or a myriad of variations around that come up

with a compile
error OR don't work!

Anyone got any thoughts on this?

Regards
John Baker




No Name

Range Reference in Visual Basic
 
try

If Target.Address = "$F$5" OR Target.Address = "$F$6" Then
Run "buttonchange"
End If

regards ojv
-----Original Message-----
Hi:

I have the following worksheet based macro in VBA:


Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Address = "$F$5" Then
Run "buttonchange"
End If
End Sub

I want to expand the target address to F5 OR F6, and

have no idea how to do it. Whatever I
try $F$5:$F$6, $F$5 OR $F$6 or a myriad of variations

around that come up with a compile
error OR don't work!

Anyone got any thoughts on this?

Regards
John Baker
.


Gord Dibben

Range Reference in Visual Basic
 
John

Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Address = "$F$5" Or Target.Address = "$F$6" Then
Run "buttonchange"
End If
End Sub

Gord Dibben XL2002

On Sat, 22 Nov 2003 13:18:12 GMT, John Baker wrote:

Hi:

I have the following worksheet based macro in VBA:


Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Address = "$F$5" Then
Run "buttonchange"
End If
End Sub

I want to expand the target address to F5 OR F6, and have no idea how to do it. Whatever I
try $F$5:$F$6, $F$5 OR $F$6 or a myriad of variations around that come up with a compile
error OR don't work!

Anyone got any thoughts on this?

Regards
John Baker



Dana DeLouis[_3_]

Range Reference in Visual Basic
 
Just to give another option...

Private Sub Worksheet_Change(ByVal Target As Range)
Select Case Target.Address(False, False)
Case "F5", "F6"
Run "buttonchange"
End Select
End Sub

--
Dana DeLouis
Using Windows XP & Office XP
= = = = = = = = = = = = = = = = =


"John Baker" wrote in message
...
Hi:

I have the following worksheet based macro in VBA:


Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Address = "$F$5" Then
Run "buttonchange"
End If
End Sub

I want to expand the target address to F5 OR F6, and have no idea how to

do it. Whatever I
try $F$5:$F$6, $F$5 OR $F$6 or a myriad of variations around that come up

with a compile
error OR don't work!

Anyone got any thoughts on this?

Regards
John Baker





All times are GMT +1. The time now is 05:33 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com