#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Loop help


I wonder if someone can help me out, I am looping through a range o
cells using the code below. My question is, when the loop identifies
particular cell in the range that doesnt meet the criteria set out i
my code, how do I go about identifying the cell and for example shadin
the cell and displaying a messagebox to the user?

Any help is much appreciated!
Ben


----------------------------------------------------------------
Dim myString As Range
Dim TrimString As String

For Each myString In Range("B2:B10")
TrimString = Trim(myString)

If Len(TrimString) = 16 Or Len(TrimString) = 10 Then
Else

MsgBox myString & "incorrect, doesnt equal 16 or 10, pleas
enter a correct value:"
myString = InputBox("Enter the correct value")
End If

Next myString
MsgBox "finished!"
Unload Me

End Su

--
benjammin
-----------------------------------------------------------------------
benjammind's Profile: http://www.excelforum.com/member.php...fo&userid=1821
View this thread: http://www.excelforum.com/showthread.php?threadid=55641

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Loop help

Dim myString As Range
Dim TrimString As String

For Each myString In Range("B2:B10")
TrimString = Trim(myString)

If Len(TrimString) = 16 Or Len(TrimString) = 10 Then
Else

MsgBox "Cell: " & myString.Address & ", Value: " &myString & _
"incorrect, doesnt equal 16 or 10, please enter a correct
value:"
myString = InputBox("Enter the correct value")
End If

Next myString
MsgBox "finished!"
Unload Me

End Sub

I would use conditional formatting to highlight cells out of range.



--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"benjammind" wrote
in message ...

I wonder if someone can help me out, I am looping through a range of
cells using the code below. My question is, when the loop identifies a
particular cell in the range that doesnt meet the criteria set out in
my code, how do I go about identifying the cell and for example shading
the cell and displaying a messagebox to the user?

Any help is much appreciated!
Ben


----------------------------------------------------------------
Dim myString As Range
Dim TrimString As String

For Each myString In Range("B2:B10")
TrimString = Trim(myString)

If Len(TrimString) = 16 Or Len(TrimString) = 10 Then
Else

MsgBox myString & "incorrect, doesnt equal 16 or 10, please
enter a correct value:"
myString = InputBox("Enter the correct value")
End If

Next myString
MsgBox "finished!"
Unload Me

End Sub


--
benjammind
------------------------------------------------------------------------
benjammind's Profile:

http://www.excelforum.com/member.php...o&userid=18217
View this thread: http://www.excelforum.com/showthread...hreadid=556417



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,646
Default Loop help

myString.Interior.Colorindex = 15 'this is light grey

Regards,
Stefi

€˛benjammind€¯ ezt Ć*rta:


I wonder if someone can help me out, I am looping through a range of
cells using the code below. My question is, when the loop identifies a
particular cell in the range that doesnt meet the criteria set out in
my code, how do I go about identifying the cell and for example shading
the cell and displaying a messagebox to the user?

Any help is much appreciated!
Ben


----------------------------------------------------------------
Dim myString As Range
Dim TrimString As String

For Each myString In Range("B2:B10")
TrimString = Trim(myString)

If Len(TrimString) = 16 Or Len(TrimString) = 10 Then
Else

MsgBox myString & "incorrect, doesnt equal 16 or 10, please
enter a correct value:"
myString = InputBox("Enter the correct value")
End If

Next myString
MsgBox "finished!"
Unload Me

End Sub


--
benjammind
------------------------------------------------------------------------
benjammind's Profile: http://www.excelforum.com/member.php...o&userid=18217
View this thread: http://www.excelforum.com/showthread...hreadid=556417


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Loop help


Thanks for the responses, one thing I forgot to add, once I have
identified, and shaded, the particular cell I want excel to jump/scroll
down to that particular cell.

For example if cells 1 - 49 are displayed on the screen and the code
highlights cell A189 I want excel to go to this location
automatically.

Again, your help is appreciated.
Ben


--
benjammind
------------------------------------------------------------------------
benjammind's Profile: http://www.excelforum.com/member.php...o&userid=18217
View this thread: http://www.excelforum.com/showthread...hreadid=556417

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Loop help

Dim myString As Range
Dim TrimString As String

For Each myString In Range("B2:B10")
TrimString = Trim(myString)

If Len(TrimString) = 16 Or Len(TrimString) = 10 Then
Else

MsgBox "Cell: " & myString.Address & ", Value: " &myString & _
"incorrect, doesnt equal 16 or 10, please enter a correct value:"

myString.Select
myString = InputBox("Enter the correct value")
End If

Next myString
MsgBox "finished!"
Unload Me

End Sub


--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"benjammind" wrote
in message ...

Thanks for the responses, one thing I forgot to add, once I have
identified, and shaded, the particular cell I want excel to jump/scroll
down to that particular cell.

For example if cells 1 - 49 are displayed on the screen and the code
highlights cell A189 I want excel to go to this location
automatically.

Again, your help is appreciated.
Ben


--
benjammind
------------------------------------------------------------------------
benjammind's Profile:

http://www.excelforum.com/member.php...o&userid=18217
View this thread: http://www.excelforum.com/showthread...hreadid=556417





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,646
Default Loop help

myString.Interior.Colorindex = 15 'this is light grey
myString.Select

Stefi


€˛benjammind€¯ ezt Ć*rta:


Thanks for the responses, one thing I forgot to add, once I have
identified, and shaded, the particular cell I want excel to jump/scroll
down to that particular cell.

For example if cells 1 - 49 are displayed on the screen and the code
highlights cell A189 I want excel to go to this location
automatically.

Again, your help is appreciated.
Ben


--
benjammind
------------------------------------------------------------------------
benjammind's Profile: http://www.excelforum.com/member.php...o&userid=18217
View this thread: http://www.excelforum.com/showthread...hreadid=556417


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
Find loop doesn't loop JSnow Excel Discussion (Misc queries) 2 June 24th 09 08:28 PM
Advancing outer Loop Based on criteria of inner loop ExcelMonkey Excel Programming 1 August 15th 05 05:23 PM
Loop Function unable to loop Junior728 Excel Programming 1 July 28th 05 10:23 AM
Problem adding charts using Do-Loop Until loop Chris Bromley[_2_] Excel Programming 2 May 23rd 05 01:31 PM
HELP!!!! Can't stop a loop (NOT an infinite loop) TBA[_2_] Excel Programming 3 December 14th 03 03:33 PM


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