Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default multiple cells in a loop

I have the following code in a cell:
rivate Sub Workbook_beforeclose(Cancel As Boolean)
Dim j As Integer


If Trim(Me.Worksheets("competency").Range("C3").Value ) = "" Then
MsgBox "Cell C3 is empty. Please fill it"
Cancel = True
Exit Sub
End If


For j = 1 To Len(Me.Worksheets("competency").Range("C3"))
If ((Asc(UCase(Mid(Me.Worksheets("competency").Range( "C3").Value
j, 1))) Asc("Z")) Or _

(Asc(UCase(Mid(Me.Worksheets("competency").Range(" C3").Value, j, 1)))
Asc("A"))) _
And (Mid(Me.Worksheets("competency").Range("C3").Value
j, 1) < " ") Then
MsgBox "Cell C3 contains illegal characters, only letters"
Cancel = True
Exit Sub
End If
Next j

If I want to apply this code to mulptiple cells where should I put th
other code? Should it be part of J loop, or should I make another one
I've tried it either way and it has not worked, so if anyone can b
specific and help me I would GREATLY appreciate it

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default multiple cells in a loop

Private Sub Workbook_beforeclose(Cancel As Boolean)
Dim sh as worksheet, cell as Range
Dim s1 as String
set sh = me.worksheets("competency")
for each cell in sh.Range("C3:C10,D9,F15")
if isempy(cell) then
msgbox Cell.Address & " is empty, please fill it"
cancel = true
end if
s1 = cell.Value
if s1 Like "*[0-9]*" then
MsgBox "Cell " & cell.address & " contains illegal characters, only
letters"
cancel = True
end if
Next
End Sub

--
Regards,
Tom Ogilvy


"jmorgs " wrote in message
...
I have the following code in a cell:
rivate Sub Workbook_beforeclose(Cancel As Boolean)
Dim j As Integer


If Trim(Me.Worksheets("competency").Range("C3").Value ) = "" Then
MsgBox "Cell C3 is empty. Please fill it"
Cancel = True
Exit Sub
End If


For j = 1 To Len(Me.Worksheets("competency").Range("C3"))
If ((Asc(UCase(Mid(Me.Worksheets("competency").Range( "C3").Value,
j, 1))) Asc("Z")) Or _

(Asc(UCase(Mid(Me.Worksheets("competency").Range(" C3").Value, j, 1))) <
Asc("A"))) _
And (Mid(Me.Worksheets("competency").Range("C3").Value ,
j, 1) < " ") Then
MsgBox "Cell C3 contains illegal characters, only letters"
Cancel = True
Exit Sub
End If
Next j

If I want to apply this code to mulptiple cells where should I put the
other code? Should it be part of J loop, or should I make another one?
I've tried it either way and it has not worked, so if anyone can be
specific and help me I would GREATLY appreciate it!


---
Message posted from http://www.ExcelForum.com/



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
How can I loop through a the values in multiple rows EMarre Excel Discussion (Misc queries) 6 May 13th 10 01:50 PM
Setting Multiple Variables with a loop jlclyde Excel Discussion (Misc queries) 6 November 11th 09 09:40 PM
Use a loop to create multiple Charts - Suggestions ? APOEL Charts and Charting in Excel 1 July 29th 06 03:36 AM
VLOOKUP loop multiple times Lenny Excel Worksheet Functions 3 September 28th 05 10:31 AM
VBA loop cells Adrie Rahanra Excel Programming 1 September 30th 03 10:22 AM


All times are GMT +1. The time now is 11:17 AM.

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"