Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / New Users / November 2006

Tip: Looking for answers? Try searching our database.

Excel VB Code seems to not be looping

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
bobbly_bob@hotmail.com - 28 Nov 2006 05:15 GMT
Alrighty, not sure why this isn't working but I've only been reading up
on this lately.

What I need the code to do is to go through the range I2:I500 and if it
comes across a cell value, bring up a menu with the value two columns
across from the cell where a 1 was found, ask the question about
marking the cell, then move on to the next cell when the buttons have
been pressed.

At the moment, nothing happens at all when I try to run it.

Cheers

Sub Message_box_test()

Dim MyRange As Range
Set MyRange = Worksheets("Sheet1").Range("I2:I500")

For Each cell In MyRange
  If ActiveCell.Offset(1, 0).Value = 1 Then

Msg = ActiveCell.Offset(0, 2).Value & vbCrLf & vbCrLf & "Would you like
this client to be marked as won?" & vbCrLf & vbCrLf & vbCrLf &
"(Hitting cancel will leave quote unmarked)"

Response = MsgBox(Msg, vbYesNoCancel + vbQuestion, Title)

If Response = vbNo Then

MsgBox "You Clicked No." & vbCrLf & vbCrLf & "Client will be marked as
not won."

End If

If Response = vbCancel Then

MsgBox "You clicked Cancelled." & vbCrLf & vbCrLf & "Client will not
yet be marked."

End If

MsgBox "You clicked Yes." & vbCrLf & vbCrLf & "Client will be marked as
won."

End If

Next

End Sub
Nick Hodge - 28 Nov 2006 07:30 GMT
Bob

During a for each...next loop the selection and therefore the ActiveCell
doesn't change.

Add a variable at the top

Dim myCell as Range

(This replaces the cell reference you use as using cell can be confused with
the cell property)

So you will now have

For Each myCell in myRange

Then replace all ActiveCell references with myCell

If myCell.Offset(1, 0).Value = 1 Then

Signature

HTH
Nick Hodge
Microsoft MVP - Excel
Southampton, England
nick_hodgeTAKETHISOUT@zen.co.ukANDTHIS
www.nickhodge.co.uk

> Alrighty, not sure why this isn't working but I've only been reading up
> on this lately.
[quoted text clipped - 45 lines]
>
> End Sub

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.