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

I have the folowing code that adds a string to the end of each item i
creates which works well. Notice my array value range is from 100 t
144. I now have a need to skip multiple numbers that are included i
that range. i.e. 119-135-137-139

In each case I would just like the code to increment to the nex
permissable value following the logic of the original. (The code look
to see if it is distinct before assigning a cell)


Can't figure it out


Dim arr(100 To 144) As String
Dim arr1, num
Dim rng As Range, cell As Range


For i = 1 To 377
For Each cell In Rows(i).Columns("K:AA")
Set rng = Nothing
If cell.Value = "PACK" Then
Set rng = cell
Exit For
End If
Next
If Not rng Is Nothing Then
For j = 100 To 144 Step 1
num = ""
If Len(Trim(arr(j))) = 0 Then
num = j
arr(num) = "PK"
Exit For
End If
Next
If num = "" Then num = "PPI"
For Each cell In Range(rng, Cells(rng.Row, "AA"))
If cell.Value = "PACK" Then
cell.Value = "PK" & num
End If
Next
End If
Nex

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default How to skip numbers in a for next loop

'---------------------------------------------------------------------
For n = 100 To 144
If n < 119 And n < 135 And n < 137 And n < 139 Then
'---------------------------------------------------------------------

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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default How to skip numbers in a for next loop

Here's a simple revision to your code:

....
For j = 100 To 144 Step 1
If Instr("119-135-137-139",Trim(Str(j))) then Goto skip
num = ""
If Len(Trim(arr(j))) = 0 Then
num = j
arr(num) = "PK"
Exit For
End If
skip: Next
....

Regards


-----Original Message-----
I have the folowing code that adds a string to the end of

each item it
creates which works well. Notice my array value range is

from 100 to
144. I now have a need to skip multiple numbers that are

included in
that range. i.e. 119-135-137-139

In each case I would just like the code to increment to

the next
permissable value following the logic of the original.

(The code looks
to see if it is distinct before assigning a cell)


Can't figure it out


Dim arr(100 To 144) As String
Dim arr1, num
Dim rng As Range, cell As Range


For i = 1 To 377
For Each cell In Rows(i).Columns("K:AA")
Set rng = Nothing
If cell.Value = "PACK" Then
Set rng = cell
Exit For
End If
Next
If Not rng Is Nothing Then
For j = 100 To 144 Step 1
num = ""
If Len(Trim(arr(j))) = 0 Then
num = j
arr(num) = "PK"
Exit For
End If
Next
If num = "" Then num = "PPI"
For Each cell In Range(rng, Cells(rng.Row, "AA"))
If cell.Value = "PACK" Then
cell.Value = "PK" & num
End If
Next
End If
Next


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

.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default How to skip numbers in a for next loop

Hi
try the following

Dim arr(100 To 144) As String
Dim arr1, num
Dim rng As Range, cell As Range

For i = 1 To 377
For Each cell In Rows(i).Columns("K:AA")
Set rng = Nothing
If cell.Value = "PACK" Then
Set rng = cell
Exit For
End If
Next

If Not rng Is Nothing Then
For j = 100 To 144 Step 1
Case select j
Case 119,135,137,139
'do nothing
Case else
num = ""
If Len(Trim(arr(j))) = 0 Then
num = j
arr(num) = "PK"
Exit For
End If
end Select
Next


If num = "" Then num = "PPI"
For Each cell In Range(rng, Cells(rng.Row, "AA"))
If cell.Value = "PACK" Then
cell.Value = "PK" & num
End If
Next
End If
Next



--
Regards
Frank Kabel
Frankfurt, Germany

I have the folowing code that adds a string to the end of each item

it
creates which works well. Notice my array value range is from 100 to
144. I now have a need to skip multiple numbers that are included in
that range. i.e. 119-135-137-139

In each case I would just like the code to increment to the next
permissable value following the logic of the original. (The code

looks
to see if it is distinct before assigning a cell)


Can't figure it out


Dim arr(100 To 144) As String
Dim arr1, num
Dim rng As Range, cell As Range


For i = 1 To 377
For Each cell In Rows(i).Columns("K:AA")
Set rng = Nothing
If cell.Value = "PACK" Then
Set rng = cell
Exit For
End If
Next
If Not rng Is Nothing Then
For j = 100 To 144 Step 1
num = ""
If Len(Trim(arr(j))) = 0 Then
num = j
arr(num) = "PK"
Exit For
End If
Next
If num = "" Then num = "PPI"
For Each cell In Range(rng, Cells(rng.Row, "AA"))
If cell.Value = "PACK" Then
cell.Value = "PK" & num
End If
Next
End If
Next


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


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default How to skip numbers in a for next loop

Thanks to everyone that responded I used a combination of your code an
it works great.

Thanks

--
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
SKIP PAGE NUMBERS IN EXCEL Bee Excel Worksheet Functions 0 April 2nd 07 06:52 AM
my numbers go from 99 and then skip to 1000's? Kerri Excel Discussion (Misc queries) 3 March 16th 06 04:05 PM
Sum and Skip Negative Numbers AlDeb Excel Worksheet Functions 4 July 20th 05 04:58 PM
Average/Min column of numbers, but skip 0's and Null's in the form JT Excel Worksheet Functions 1 November 4th 04 03:25 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 04:45 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"