for next with block of 5

User avatar
sal21
PlatinumLounger
Posts: 4362
Joined: 26 Apr 2010, 17:36

for next with block of 5

Post by sal21 »

I loop a with:

x=50

for i=1 to x
...

next x

possible to set a block of 5 for i...

example:

i=5
then print i & "A"

next block of i=5

then print i & "B"

ecc...

to the end:

1 A
2 A
3 A
4 A
5 A
6 B
7 B
8 B
9 B
10 B
11 C
12 C
...
Ecc

note:
using the standard sequntial letter of alphabet

User avatar
HansV
Administrator
Posts: 78530
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: for next with block of 5

Post by HansV »

Code: Select all

    Dim x As Long
    Dim i As Long
    For i = 1 To x
        Debug.Print i & Chr(64 + (i - 1) \ 5)
    Next i
Best wishes,
Hans

User avatar
SpeakEasy
4StarLounger
Posts: 562
Joined: 27 Jun 2021, 10:46

Re: for next with block of 5

Post by SpeakEasy »

Hans - almost exactly the same as the code I was just about to post!

User avatar
sal21
PlatinumLounger
Posts: 4362
Joined: 26 Apr 2010, 17:36

Re: for next with block of 5

Post by sal21 »

HansV wrote:
31 Oct 2023, 17:07

Code: Select all

    Dim x As Long
    Dim i As Long
    For i = 1 To x
        Debug.Print i & Chr(64 + (i - 1) \ 5)
    Next i
GREAT!

OPS..

with:

Dim X As Long
Dim I As Long

X = 50

For I = 1 To X
Debug.Print I & Chr(64 + (I - 1) \ 5)
Next I

i have:

1@
2@
3@
4@
5@
6A
7A
8A
9A
10A
11B
12B
13B
14B
15B
16C
17C
18C
19C
20C
21D
22D
23D
24D
25D
26E
27E
28E
29E
30E
31F
32F
33F
34F
35F
36G
37G
38G
39G
40G
41H
42H
43H
44H
45H
46I
47I
48I
49I
50I

User avatar
SpeakEasy
4StarLounger
Posts: 562
Joined: 27 Jun 2021, 10:46

Re: for next with block of 5

Post by SpeakEasy »

65

User avatar
sal21
PlatinumLounger
Posts: 4362
Joined: 26 Apr 2010, 17:36

Re: for next with block of 5

Post by sal21 »

SpeakEasy wrote:
31 Oct 2023, 17:51
65
TKS, SpeakEasy .

please tell me about to understand 64 chr and 65 chr...

User avatar
SpeakEasy
4StarLounger
Posts: 562
Joined: 27 Jun 2021, 10:46

Re: for next with block of 5

Post by SpeakEasy »

65 is the ASCII/ANSI value for "A"

User avatar
p45cal
2StarLounger
Posts: 151
Joined: 11 Jun 2012, 20:37

Re: for next with block of 5

Post by p45cal »

What happens after 130Z?
This?:
2023-11-02_140058.jpg
or perhaps this? (like the column names at the top of an Excel sheet):
2023-11-02_140312.jpg

If so:

Code: Select all

Debug.Print i & Split(Cells(1, (i - 1) \ 5 + 1).Address, "$")(1)
You do not have the required permissions to view the files attached to this post.

User avatar
SpeakEasy
4StarLounger
Posts: 562
Joined: 27 Jun 2021, 10:46

Re: for next with block of 5

Post by SpeakEasy »

sal21 uses vb6 not Excel, so that rather cunning solution sadly won't work for them

User avatar
sal21
PlatinumLounger
Posts: 4362
Joined: 26 Apr 2010, 17:36

Re: for next with block of 5

Post by sal21 »

SpeakEasy wrote:
02 Nov 2023, 15:39
sal21 uses vb6 not Excel, so that rather cunning solution sadly won't work for them
Infact...
In other case the loop is refered to the numbers of a rooms of b&b. Have max 50 room...
I think 50 the max number in a standard b&b