|
-
Oct 1st, 2009, 08:16 AM
#1
Thread Starter
Member
Excel VBA Question
how can I create a excel vba to display the following numbers to 170
3
7
13
17
23
27
33
37
43
47
...
130
170
I tried to do it with
Code:
for x = 3, x <= 170 Step 3
{
x= x + 1
}
Next x
But this doesn't work. how do I fix this? this was an interview question.
-
Oct 1st, 2009, 10:13 AM
#2
New Member
Re: Excel VBA Question
try
x=3
y=7
...
x=x+10
y=y+10
-
Oct 1st, 2009, 10:21 AM
#3
Re: Excel VBA Question
Moved To Office Development
-
Oct 1st, 2009, 10:26 AM
#4
Re: Excel VBA Question
Two things...
I think that the series that you want to generate is
7
13
17
23
27
33
37
43
47
53
57
63
67
73
77
83
87
93
97
103
107
113
117
123
127
133
137
143
147
153
157
163
167
173
If yes then try this...
vb Code:
Sub GenerateSeries() Dim i As Long, j As Long, boolCheck As Boolean, boolExit As Boolean i = 3 j = 1 '~~> Store it in Excel Cell A1 Range("A" & j).Value = i '~~> Generate Series Do While boolExit = False If boolCheck = False Then i = i + 4 boolCheck = True ElseIf boolCheck = True Then i = i + 6 boolCheck = False End If Range("A" & j).Value = i j = j + 1 '~~> Exit loop when end of number reached If i > 170 Then boolExit = True Loop End Sub
Last edited by Siddharth Rout; Oct 1st, 2009 at 10:29 AM.
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Oct 1st, 2009, 12:20 PM
#5
Addicted Member
Re: Excel VBA Question
I don't understand your pattern, because
doesn't logically fit into
7
13
17
23
27
33
37
43
47
...
Starting from 3, you are getting every number which ends in either 3 or 7. 130 & 170 doesn't fit that. Unless I am misunderstanding how you arrived at your pattern.
-
Oct 1st, 2009, 01:56 PM
#6
Re: Excel VBA Question
Mark I guess that was a typo... guess
I have put the actual series in my last post...
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Oct 1st, 2009, 02:35 PM
#7
Addicted Member
Re: Excel VBA Question
 Originally Posted by koolsid
Mark I guess that was a typo... guess
I have put the actual series in my last post...
Yeah, I'd guess it was too, but you never know.
Another solution for jazlady:
Dim x As Integer
Dim y As Integer
For x = 3 To 173 Step 10
y = x + 4
If (x > 173) Then Exit For
Debug.Print x
If (y > 173) Then Exit For
Debug.Print y
Next x
-
Oct 1st, 2009, 02:46 PM
#8
Re: Excel VBA Question
Nice one Mark
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Oct 1st, 2009, 03:57 PM
#9
Re: Excel VBA Question
Code:
For i = 0 To 16
Cells(2 * i + 1, 1) = i * 10 + 3
Cells(2 * i + 2, 1) = i * 10 + 7
Next
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|