Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default simple visual basic question - multiple If statements

Hello,

I have a code that works perfect for what I am trying to do, but I
don't know how to make it work for more than one field. The
Worksheet_Change part works but Worksheet_Change2 doesn't seem to do
anything.

In the sheet portion of the visual basic I have the following code:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$L$72" Then
If IsEmpty(Target) Then Target = "Intel Celeron at 700MHz - $500"
End If
End Sub

Private Sub Worksheet_Change2(ByVal Target As Range)
If Target.Address = "$L$73" Then
If IsEmpty(Target) Then Target = "32KB - $100"
End If
End Sub


Why doesn't the second part work? Is this code just in bad form?

Thanks for your help!

Sean

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default simple visual basic question - multiple If statements

You can not have a Change2. That is not recognized event code... Try
something like this...

Private Sub Worksheet_Change(ByVal Target As Range)
Select Case Target.Address
Case "$L$72", "$L$100"
If IsEmpty(Target) Then Target = "Intel Celeron at 700MHz - $500"
Case "$L$73"
If IsEmpty(Target) Then Target = "32KB - $100"
Case "$A$1", "$A$10"
MsgBox "Tada"
End Select

If Not Intersect(Target, Range("B1:B100")) Is Nothing Then MsgBox "B Stuff"

End Sub

--
HTH...

Jim Thomlinson


" wrote:

Hello,

I have a code that works perfect for what I am trying to do, but I
don't know how to make it work for more than one field. The
Worksheet_Change part works but Worksheet_Change2 doesn't seem to do
anything.

In the sheet portion of the visual basic I have the following code:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$L$72" Then
If IsEmpty(Target) Then Target = "Intel Celeron at 700MHz - $500"
End If
End Sub

Private Sub Worksheet_Change2(ByVal Target As Range)
If Target.Address = "$L$73" Then
If IsEmpty(Target) Then Target = "32KB - $100"
End If
End Sub


Why doesn't the second part work? Is this code just in bad form?

Thanks for your help!

Sean


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default simple visual basic question - multiple If statements

On Mar 15, 11:44 am, Jim Thomlinson <James_Thomlin...@owfg-Re-Move-
This-.com wrote:
You can not have a Change2. That is not recognized event code... Try
something like this...

Private Sub Worksheet_Change(ByVal Target As Range)
Select Case Target.Address
Case "$L$72", "$L$100"
If IsEmpty(Target) Then Target = "Intel Celeron at 700MHz - $500"
Case "$L$73"
If IsEmpty(Target) Then Target = "32KB - $100"
Case "$A$1", "$A$10"
MsgBox "Tada"
End Select

If Not Intersect(Target, Range("B1:B100")) Is Nothing Then MsgBox "B Stuff"

End Sub

--
HTH...

Jim Thomlinson



" wrote:
Hello,


I have a code that works perfect for what I am trying to do, but I
don't know how to make it work for more than one field. The
Worksheet_Change part works but Worksheet_Change2 doesn't seem to do
anything.


In the sheet portion of the visual basic I have the following code:


Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$L$72" Then
If IsEmpty(Target) Then Target = "Intel Celeron at 700MHz - $500"
End If
End Sub


Private Sub Worksheet_Change2(ByVal Target As Range)
If Target.Address = "$L$73" Then
If IsEmpty(Target) Then Target = "32KB - $100"
End If
End Sub


Why doesn't the second part work? Is this code just in bad form?


Thanks for your help!


Sean- Hide quoted text -


- Show quoted text -


That's great Jim, thanks a lot for your help and your explanation.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 469
Default simple visual basic question - multiple If statements

If I follow your responce. I should be able to use case to allow code to copy
to 2 or 3 different worksheets as needed ? New to event procedure.

"Jim Thomlinson" wrote:

You can not have a Change2. That is not recognized event code... Try
something like this...

Private Sub Worksheet_Change(ByVal Target As Range)
Select Case Target.Address
Case "$L$72", "$L$100"
If IsEmpty(Target) Then Target = "Intel Celeron at 700MHz - $500"
Case "$L$73"
If IsEmpty(Target) Then Target = "32KB - $100"
Case "$A$1", "$A$10"
MsgBox "Tada"
End Select

If Not Intersect(Target, Range("B1:B100")) Is Nothing Then MsgBox "B Stuff"

End Sub

--
HTH...

Jim Thomlinson


" wrote:

Hello,

I have a code that works perfect for what I am trying to do, but I
don't know how to make it work for more than one field. The
Worksheet_Change part works but Worksheet_Change2 doesn't seem to do
anything.

In the sheet portion of the visual basic I have the following code:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$L$72" Then
If IsEmpty(Target) Then Target = "Intel Celeron at 700MHz - $500"
End If
End Sub

Private Sub Worksheet_Change2(ByVal Target As Range)
If Target.Address = "$L$73" Then
If IsEmpty(Target) Then Target = "32KB - $100"
End If
End Sub


Why doesn't the second part work? Is this code just in bad form?

Thanks for your help!

Sean


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
A simple visual basic program wilchong via OfficeKB.com New Users to Excel 2 October 22nd 08 09:16 AM
Visual Basic Question ALEX Excel Worksheet Functions 3 February 6th 07 11:46 AM
Visual Basic Question Peter W Soady \(UK\) Excel Discussion (Misc queries) 1 October 25th 06 06:26 PM
Problem with a very simple code in Visual basic Vepa Excel Programming 4 January 25th 06 03:42 PM
Need code for Excel Simple Visual Basic Macro to select next avai. Marco Margaritelli[_3_] Excel Programming 6 November 2nd 04 10:26 PM


All times are GMT +1. The time now is 07:22 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"