Scroll to cell value

tjktm

New Member
Joined
Mar 2, 2016
Messages
31
My spreadsheet is set up to scroll from a button to a certain row number. That row contains specific information. However, when new rows are added or deleted, the button scrolls to rows above or below the correct row. I have the following code now:

Sub View_9()
' View_Total Macro
ActiveWindow.ScrollRow = 298

This code works great as long as no rows are added or deleted.

Need code to scroll to a variable cell with a specific value in column A. The specific value will be "R.1" , "R.2", etc. . Those values could be changed if they complicate the code.

Thanks for any help

TJ
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
You can try this from an active-x command button on the sheet your specific value is on.
Code:
Private Sub CommandButton1_Click()
Dim Fnd As Variant, fndRng As Range
Fnd = InputBox("What value in col A do you want to scroll to?")
If Fnd = "" Then Exit Sub  'cancel was clicked
Set fndRng = Columns("A").Find(Fnd)
If Not fndRng Is Nothing Then
    ActiveWindow.ScrollRow = fndRng.Row
Else
    MsgBox "Can't find " & Fnd & " in column A"
End If
End Sub
 
Upvote 0
Thanks. but is there a way to do this so i don't have to input the value? I think my description above was misleading. The value will stay constant on the row to scroll to. When i press my command button labeled "R.8" , i need it to scroll to the row that has "R.8" in Column A.

is that possible?
 
Upvote 0
Hard to beat Joe's code for what you originally requested. The following tweak should take care of your refined request.

Private Sub CommandButton1_Click()
Dim Fnd As Variant, fndRng As Range
Fnd = CommandButton1.caption
If Fnd = "" Then Exit Sub 'cancel was clicked
Set fndRng = Columns("A").Find(Fnd)
If Not fndRng Is Nothing Then
ActiveWindow.ScrollRow = fndRng.Row
Else
MsgBox "Can't find " & Fnd & " in column A"
End If
End Sub
 
Upvote 0
If you have a lot of commandbuttons that have this same functionality, you should consider adding them to a class, so that they can all use the same code.
 
Upvote 0
Thank you. it works perfect. I do have 16 of those command buttons that need to do the same thing but i'm not familiar with adding them to a class. Thanks for the heads up, I'll look around for some info on this forum.

Thanks again!
 
Upvote 0
What type of Buttons are you using?
ActiveX, Form controls, or something else?
 
Upvote 0
If the buttons are labelled with the value you want to find, you can use this code on all buttons
Code:
Sub ScrollToRow()
Dim Fnd As Variant, fndRng As Range
Fnd = ActiveSheet.Shapes(Application.Caller).AlternativeText
If Fnd = "" Then Exit Sub  'cancel was clicked
Set fndRng = Columns("A").Find(Fnd)
If Not fndRng Is Nothing Then
    ActiveWindow.ScrollRow = fndRng.Row
Else
    MsgBox "Can't find " & Fnd & " in column A"
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,897
Messages
6,175,269
Members
452,628
Latest member
dd2

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