To start with, I have never seen anything like this in 15 years of Excel programming.
On a lighter note I feel that this particular Excel File is Haunted :P
On a serious note, I really can't understand what's going on.
Problem
The code (I didn't write it) runs and hides the rows based on a condition. When you click on any cell except in column C in row 59
, it shows that it is from row 58
. Only in cell C, it shows the correct address.
Screenshot
What have I tried?
ScreenUpdating
issue but as you can see the code, that this is ruled out.?Activecell.Row
. I got 58,59,58,58
Code
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Dim i, j, k, lastrow As Long
Dim finlast As Long
Application.ScreenUpdating = False
'Income_Disc
lastrow = Sheets("Financial_Disc1").Range("E65536").End(xlUp).Row
finlast = Sheets("Financial_Disc").Range("A65536").End(xlUp).Value + 1
If Target.Column = 9 And Target.Row = 1 Then
'Unhide Rows if I1 is double clicked
Sheets("Financial_Disc1").Rows("1:65536").EntireRow.Hidden = False
Else
If Target.Row > 7 And Target.Row < lastrow Then
If Target.Column = 9 Then
'Hide Rows
For j = Target.Row To lastrow
If Sheets("Financial_Disc1").Range("B" & CStr(j + 1)) <> "" Then
'Hide Rows
Sheets("Financial_Disc1").Range("A" & CStr(j)).EntireRow.Hidden = True
Exit For
Else
'Hide Rows
Sheets("Financial_Disc1").Range("A" & CStr(j)).EntireRow.Hidden = True
End If
Next j
End If
End If
End If
Sheets("Financial_Disc1").Range("A8:A65536").ClearContents
For i = 8 To lastrow
If Sheets("Financial_Disc1").Range("A" & CStr(i)).EntireRow.Hidden = True Then
If Sheets("Financial_Disc1").Range("B" & CStr(i)) <> "" Then
Sheets("Financial_Disc1").Range("A" & CStr(i)) = ""
End If
Else
If Sheets("Financial_Disc1").Range("B" & CStr(i)) <> "" Then
Sheets("Financial_Disc1").Range("A" & CStr(i)) = finlast
finlast = finlast + 1
End If
End If
Next i
Application.ScreenUpdating = True
End Sub
Misc Points
As you can see this file has columns in reverse because it is from one of my client in Saudi Arabia.
My Question
Can anyone see what could be the problem? Or I should simply dismiss it as a "Rare" bug?
Please check the row for merged cells - traversing them can cause row "shifts"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With