VBA for next loops

rinneii

New Member
Joined
Mar 20, 2019
Messages
18
EDIT: I meant VBA !!! I tried doing VBA: but I ended up putting an L instead >_>

For one of my assignments I need to do as follows:

Obtain winning numbers through last row in column G: Type Winner in column G for any row you choose. Write a macro to capture the six winning numbers in that row in an array, and display in H3:H8 with a header “Winning Numbers” in H2.
Solution
DIM statements: lottery(1 to 6) as Integer; i as Integer, j As Integer, Lrow As Integer, wn_header As String
Delete column H to erase any numbers in column H
Use the last row technique to find the row with Winner in column G, and put it in variable Lrow
For-Next loop from column A to column F to capture winning numbers in lottery(1) to lottery(6). Designate ranges with Cells(row,column). Use Lrow for the row, and counter i for the column.
Put text “Winning Numbers” in variable wn_header
Put wn_header in cell H2
For-Next loop to enter lottery(1) to lotter(6) in cells H3:H8. Use counter starting at 3, and going to 8 (place in row position of Cells way of addressing ranges). Column position is 8.


I'm having issues with the for next loop. I'm not exactly sure how to do it :'|

Here's the data we start off with. I added "Winner" already.

[TABLE="width: 454"]
<tbody>[TR]
[TD]Num 1[/TD]
[TD]Num 2[/TD]
[TD]Num 3[/TD]
[TD]Num 4[/TD]
[TD]Num 5[/TD]
[TD]Powerball[/TD]
[TD]Status[/TD]
[/TR]
[TR]
[TD]51[/TD]
[TD]35[/TD]
[TD]48[/TD]
[TD]22[/TD]
[TD]5[/TD]
[TD]2[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]13[/TD]
[TD]47[/TD]
[TD]39[/TD]
[TD]49[/TD]
[TD]57[/TD]
[TD]19[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]29[/TD]
[TD]59[/TD]
[TD]50[/TD]
[TD]63[/TD]
[TD]7[/TD]
[TD]1[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]58[/TD]
[TD]66[/TD]
[TD]35[/TD]
[TD]57[/TD]
[TD]17[/TD]
[TD]18[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]47[/TD]
[TD]56[/TD]
[TD]37[/TD]
[TD]66[/TD]
[TD]22[/TD]
[TD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D]15[/TD]
[TD]9[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]25[/TD]
[TD]56[/TD]
[TD]63[/TD]
[TD]43[/TD]
[TD]4[/TD]
[TD]9[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]35[/TD]
[TD]67[/TD]
[TD]3[/TD]
[TD]69[/TD]
[TD]61[/TD]
[TD]15[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]49[/TD]
[TD]4[/TD]
[TD]28[/TD]
[TD]32[/TD]
[TD]22[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]25[/TD]
[TD]64[/TD]
[TD]22[/TD]
[TD]50[/TD]
[TD]31[/TD]
[TD]9[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
 
Last edited:

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
I assume the "Solution" is the template that the assignment wants you to follow?

If so, your code should have determined the value of LRow - it looks like 16 to me, assuming your headers are in row 1? Have you got this far?

You are then being asked to write a loop to put the six values in A16:F16 (i.e row 16 and columns 1 to 6) into your lottery() array.

What code have you tried for this?
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,286
Members
452,631
Latest member
a_potato

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top