Excel VBA Course
Excel VBA Course - From Beginner to Expert

200+ Video Lessons
50+ Hours of Video
200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course

Clear Appended Empty Rows

0

In a worksheet, is there an easy way to clear appended empty rows so only the rows with data are vertically scrolled. I believe the empty rows are added to the vertical scroll when a coluimn is selected to its maximim rows which includes empties. Undo is not an option if the file has ben saved. when the vertical scroll bar imcludes all rows up to its maximum. it becomes too sensitive in movements.

Answer
Discuss

Answers

0

Hello Essaj2000 and welcome to the forum.

If you want to limt scrolling to only the used area of the worksheet then place the following in the worksheet code window. This code assumes your data starts in "A1".

Private Sub Worksheet_Activate()

Dim LastRow As Long

' change A & M to the first and last columns of your table/data set
LastRow = Range("A:M").Find("*", searchorder:=xlByRows, searchdirection:=xlPrevious).Row

' set scroll area to only the used area
ScrollArea = "A1:M" & LastRow

' or set scroll area to the used area plus an extra 2 columns and rows
ScrollArea = "A1:O" & LastRow + 2

End Sub

To do this, open the vb editor window (Alt + F11); then in the project window click on the worksheet where you want this code; right click and select "View Code".Then copy and paste this code into the window that opens. Now each time that sheet is selected (activated) the scroll area will be set to the used area.

Note: adding data will be restricted to the rows/columns set by the scroll area.

Cheers   :-)

Discuss


Answer the Question

You must create an account to use the forum. Create an Account or Login