View Single Post
  #1   Report Post  
MrBadExcel MrBadExcel is offline
Junior Member
 
Posts: 3
Default Run-time error '424': Object required

The code below allows me highlight one row at a time. I can scroll up and down a sheet using the arrow keys.
Sometimes need to highlight two or more rows by holding shift and clicking multiple rows. The code is only allowing me to highlight one row at a time however I can select multiple rows.

When I try to preform a delete command on multiple rows I have selected I am receiving an this error code after the delete is preformed and I then select another row to highlight:
Run-time error '424': Object required

When I click DEBUG it highlights this row in the code:
For Each Dn In rng


Option Explicit
Dim rng As Range, ray
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim Dn As Range, c As Long, col As Long
col = 100
If Not rng Is Nothing Then
c = 0
For Each Dn In rng
c = c + 1
Dn.Interior.ColorIndex = ray(c, 1)
Next Dn
End If
c = 0
Set rng = Cells(Target.Row, 1).Resize(, col)
ReDim ray(1 To rng.Count, 1 To 2)
For Each Dn In rng
c = c + 1
ray(c, 1) = Dn.Interior.ColorIndex
Next Dn
Cells(Target.Row, 1).Resize(, col).Interior.ColorIndex = 6
End Sub