Selecting rows from a table

socaldwat

New Member
Joined
Oct 27, 2016
Messages
2
Hi everyone,

I couldn't find anything in the forum that could answer my question so here goes nothing...

I am recreating a table from an older board game that uses a slide rule to report numbers. During the game, the slide moves up and down according to what space you land on. However, if you hit the top of the table (e.g. You are at row #2 and the space says move Up 4), you move up 1 and then proceed to move back down 3 to fulfill the remaining spaces. I can code this by hand, but I really don't want to see how ugly the code gets when it's Move Up 20. Here's what I have so far:

ListBox1 contains the Values 1-5, and 20.
cmdUp is a toggle button (I also have a toggle button for down)
B20 contains what row number of the table the current selection is at.
B16 is what the prior value of the stock that needs to be changed. (The other stocks are coded to use VLookup to determine their values.)

Code:
Private Sub CmdOk2_Click()

Dim x As Integer


x = Range("B20").Value


Sheets("Stock Values").Select


    If cmdUp.Value = True Then
        If ListBox1.Value = 1 Then
            If x <= "1" Then
               ActiveCell.Offset(-1, 0).Select
                Sheets("Game!").Range("B16").Value = Sheets("Stock Values").ActiveCell.Value
            End If
            ActiveCell.Offset(1, 0).Select
            Sheets("Game!").Range("B16").Value = Sheets("Stock Values").ActiveCell.Value
        End If
        If ListBox1.Value = 2 Then
            If x = "1" Then
                ActiveCell.Offset(-2, 0).Select
                Sheets("Game!").Range("B16").Value = Sheets("Stock Values").ActiveCell.Value
            End If
            ElseIf x = "2" Then
                'This selection moves the table up one, and then down one, virtually doing nothing.
                End If
            Else
                ActiveCell.Offset(2, 0).Select
                Sheets("Game!").Range("B16").Value = Sheets("Stock Values").ActiveCell.Value
         End if
End Sub

I tried to think of an Algebraic way of approaching this, but I couldn't find something that would work universally.

Sorry for the noob post. And the game is "Stock Market" if that helps any.

Thank you in advance for any help.

Socaldwat
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop

Forum statistics

Threads
1,214,651
Messages
6,120,744
Members
448,989
Latest member
mariah3

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