Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Ayo Ayo is offline
external usenet poster
 
Posts: 489
Default No error message but code doesn't work

I have this Sub that I am trying to run but it keeps going back to the
beginning everytime it get to this line:

..Range("I36") = Application.WorksheetFunction.VLookup(c,
Worksheets("Goals").Range("C3:K54"), 2, False)

no errors, no messages. I can't figure out what the problem is. Any help
will be appreciated. Thanks.

Private Sub Worksheet_Change(ByVal Target As Range)

Worksheets("CENTRAL PA Charts").Activate
With ActiveSheet
For Each c In Worksheets("Goals").Range("C3:C54").Cells
If c.Value = .Range("B4") And c.Offset(0, -1).Value = .Range("B3")
Then
.Range("I36") = Application.WorksheetFunction.VLookup(c,
Worksheets("Goals").Range("C3:K54"), 2, False)
.Range("I37") = Application.WorksheetFunction.VLookup(c,
Worksheets("Goals").Range("rngGoals"), 4, False)
Exit For
End If
Next c
End With

End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default No error message but code doesn't work

Temporarily disable events
Application.EnableEvents = false
'your code
Application.EnableEvents = true

One very minor point. You are using activesheet. In this case not a problem
but if somehow you were to change the selected sheet the code could operate
on the wrong sheet. Since this code is embeded directly in a sheet you are
better off to use Me insetad of activesheet. Me will always refer to the
sheet that the code is in.
--
HTH...

Jim Thomlinson


"Ayo" wrote:

I have this Sub that I am trying to run but it keeps going back to the
beginning everytime it get to this line:

.Range("I36") = Application.WorksheetFunction.VLookup(c,
Worksheets("Goals").Range("C3:K54"), 2, False)

no errors, no messages. I can't figure out what the problem is. Any help
will be appreciated. Thanks.

Private Sub Worksheet_Change(ByVal Target As Range)

Worksheets("CENTRAL PA Charts").Activate
With ActiveSheet
For Each c In Worksheets("Goals").Range("C3:C54").Cells
If c.Value = .Range("B4") And c.Offset(0, -1).Value = .Range("B3")
Then
.Range("I36") = Application.WorksheetFunction.VLookup(c,
Worksheets("Goals").Range("C3:K54"), 2, False)
.Range("I37") = Application.WorksheetFunction.VLookup(c,
Worksheets("Goals").Range("rngGoals"), 4, False)
Exit For
End If
Next c
End With

End Sub

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
chart error message / work sheet not open ? Ron Charts and Charting in Excel 2 July 17th 07 08:16 PM
Code has been interupted - error message Jeff Excel Discussion (Misc queries) 0 May 10th 07 03:23 PM
Help with Error Message Box code Cutter[_11_] Excel Programming 2 July 9th 04 07:31 PM
Message box causing error in code Calligra[_2_] Excel Programming 6 July 9th 04 03:02 PM
Message box causing error in code Calligra Excel Programming 0 July 7th 04 02:46 PM


All times are GMT +1. The time now is 03:25 PM.

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

About Us

"It's about Microsoft Excel"