Buttons for Next previous etc

TurboDieselOne

Board Regular
Joined
Oct 29, 2008
Messages
52
Can seem to get this to work I have a Current Button Loads the form OK
Then Next Button should use the :-
CurrentRow = ActiveCell.Row
CurrentRow = CurrentRow+1
Load the Form Data...
Too many lines to list here
Its goes Ok once but then when I press next again it does nothing.

Any clues before I try tackling the Previous


Thanks

Oh I have the Userform Fields fill like example below

Me.intIndex.Text = Worksheets("Sheet1").Cells(CurrentRow, "BG").Value
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Code:
CurrentRow = ActiveCell.Row

This line resets the row.

What you need to do is retain this value so that the Next and Previous procedures can change it. One way to acheive this is to use a global variable.

Code:
[COLOR=darkblue]Public[/COLOR] CurrentRow [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]Long[/COLOR]
 
[COLOR=darkblue]Private[/COLOR] [COLOR=darkblue]Sub[/COLOR] UserForm_Initialize()
    CurrentRow = ActiveCell.Row
[COLOR=darkblue]End[/COLOR] [COLOR=darkblue]Sub[/COLOR]
 
[COLOR=darkblue]Private[/COLOR] [COLOR=darkblue]Sub[/COLOR] cmdNext_Click()
    CurrentRow = CurrentRow + 1
    MsgBox CurrentRow
    [COLOR=green]'rest of the code goes here[/COLOR]
[COLOR=darkblue]End[/COLOR] [COLOR=darkblue]Sub[/COLOR]
 
[COLOR=darkblue]Private[/COLOR] [COLOR=darkblue]Sub[/COLOR] cmdPrevious_Click()
    CurrentRow = CurrentRow - 1
    MsgBox CurrentRow
    [COLOR=green]'rest of code goes here[/COLOR]
[COLOR=darkblue]End[/COLOR] [COLOR=darkblue]Sub[/COLOR]
 
Upvote 0

Forum statistics

Threads
1,224,587
Messages
6,179,740
Members
452,940
Latest member
Lawrenceiow

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