This code used to run fine, then all of a sudden it started failing on \"method \'range of object\' _Worksheet failed\"? \' I\'m not an expert with VBA, but I can get myself
I ran into the same error message but the cause was different for me. I am only referencing the active worksheet. Apparently the default ReferenceStyle was changed for a few of my users that all have the same VBA logic. Not sure if this was a result of application updates or if multiple users managed to make the same change. Debugging the logic I found that the PrintArea representation would no longer convert to a Range.
wS.Range(wS.PageSetup.PrintArea).Address
The PrintArea value was populated but shown in a format that unfamiliar to me. Turns out it was R1C1 style instead of the default A1 style cell reference. I found another post that referenced changing the reference style in their user settings but I did not want to force that change on my users. I decided to set the reference style for this workbook each time it was opened. I hooked into Workbook_Open and used xlA1.
Application.ReferenceStyle = xlA1
The Cells are being referenced from the activesheet, not "database".
Set CR1_range = ws.Range(ws.Cells(5, CR1), ws.Cells(ws.Rows.count, CR1))
Excel VBA method range of object _global failed?
Sub kar()
Dim i, j
For i = 8 To 15
For j = 9 To 15
If (Range("ji") = Range("jj") And Range("gi") = "خريد" And Range("gj") = "فروش" And (Abs(Range("ki") - Range("kj") <= 50))) Then
Range("ui") = -(Range("ki") - Range("kj")) * hi
Range("uj") = -(Range("ki") - Range("kj")) * hj
End If
If (Range("ji") = Range("jj") And Range("gi") = "فروش" And Range("gj") = "خريد" And (Abs(Range("ki") - Range("kj")) <= 50)) Then
Range("uj").Value = -(Range("ki") - Range("kj")) * hi
Range("ui").Value = -(Range("ki") - Range("kj")) * hj
End If
Next j
Next i
End Sub