VBA: Cursor Should not go to some range ? How

  • I do not want to Hide the rows or colums to stop the screen rolling because ,



    If i hide the rows the file size become big.


    I want to disable screen rolling . Please help.


    If Scroll Bars are invisible also if I use Down arrow key it keeps moving down , SO i want to stop scrolling . Thanks

  • Put the following macro in the module attached to the worksheet (right click on the sheet tab and slect View Code). Change the range A1:J20 to be the range where you will allow the cursor. This can have several areas, for example Range("A1:D20,E5:E10,F1:F15,F20")
    Make sure that the range you designate to send the cursor if it is in a forbidden area is in the designated area or you will have an infinite loop.

    Code
    1. Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
    2. If Intersect(Target, Range("A1:J20")) Is Nothing Then Range("A1").Select
    3. End Sub
  • If it is easier to designate the forbidden cells for the cursor then use the following code instead, where B10:J20 is the forbidden area.

    Code
    1. Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
    2. If Not Intersect(Target, Range("B10:J20")) Is Nothing Then Range("A1").Select
    3. End Sub