Conditional scrolling macro

Hart

Board Regular
Joined
Jan 2, 2005
Messages
78
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hi all.
I would like to create a macro which would scroll through a table if there are too many rows to fit on the display. For example, if the table had more than 25 rows, scroll until the last row is displayed. Once the end of the table is reached, the scroll would return to the first entry in the table and repeat.
If the table had <= 25 rows, no scrolling is required.
Something like:
if rows(table1)<=25 then no scroll
else scroll to end of table (and repeat)

Thanks!
 
Run this code (any module will do) - should return true

Code:
Sub ee()
MsgBox Application.EnableEvents
End Sub
 
Upvote 0

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
After this line
Code:
Set tbl = Target.ListObject

add this line
Code:
msgbox tbl.name

Select any cell in the table and the message box containing table name should appear
 
Upvote 0
Like this?

Sub ee()
Set tbl = Target.ListObject
MsgBox tbl.Name
End Sub
 
Upvote 0
I should have been more specific...
No - add the line to the Selection_Change macro
 
Upvote 0
There is 1 other named range in my sheet but it is not a table.
 
Upvote 0
It says "Table2"
That proves that you put the code in the correct place
It also proves that the table exists and is recognised as such
Now I need to work out why the scroll is not working for you when it does for me:confused:

Can you try all versions of the code
- delete the VBA each time and then paste in the others one at a time and test them
- include the message box - at least we then know that the code is being triggered
- let me know how you get on

I will be away for about 60 minutes
- if it is still not working for you, I will send you various code snippets to see if we can unravel the mystery :confused:
 
Last edited:
Upvote 0
Hi Yongle. The 2nd and 3rd pieces of code give the table name. The first piece of code does not work. I noted that there was an "end sub" that was outside the code window which I tried adding but it still did not compile. Syntax is not my strong point!
 
Upvote 0
Hi Yongle. The 2nd and 3rd pieces of code give the table name. The first piece of code does not work. I noted that there was an "end sub" that was outside the code window which I tried adding but it still did not compile. Syntax is not my strong point!

I will offline now for about 3-4 hrs. Thanks for all your help to this point.
Hart
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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