Method Range of Object Worksheet failed error when establishing integer variable

SBF12345

Well-known Member
Joined
Jul 26, 2014
Messages
614
Greetings,

Below is the line giving me trouble. I am receiving the error "method range of object worksheet failed".

Code:
I = ws.Range(Cells(2, "A")).Row

This line exists within the below script:



Code:
Sub TRENDSHEET()

Dim ws As Worksheet
Dim PA As Workbook
Dim TA As Workbook
Dim A As Integer
Dim B As Integer
Dim D As Integer
Dim E As Integer
Dim F As Integer
Dim G As Integer
Dim H As Integer
Dim I As Integer
Dim J As Integer
Dim K As Integer
Dim L As Integer
Dim M As Integer
Dim N As Integer
Dim AA As Range
Dim BB As Range
Dim CC As Range
Dim DD As Range
Dim R1 As Range
Dim R2 As Range








Set TA = Workbooks("COMM_TREND.xls")
Set PA = Workbooks("COMM_PA.xls")








For Each ws In PA.Worksheets




A = ws.Cells(Rows.Count, "A").End(xlUp).Row


    Do Until A = 2
      
       
        If ws.Cells(A, "E").Value > Application.Large(ws.Cells((A - 10), "E").Resize(21), 2) Then
       
        
      
        Set AA = ws.Cells(A, "E")
        Set DD = ws.Cells(A, "A")
        G = AA.Row
        H = ws.Cells(A, "A").Row
    
        TA.ws.Activate
        Range("A1").Select
        Selection.End(xlDown).Offset(1, 0).Select
        Selection.Value = "ACTIVE"
            
        Range("A1").Select
        Selection.End(xlDown).Offset(0, 1).Select
        Selection.Value = DD.Value
        
        Range("A1").End(xlDown).Offset(0, 2).Select
        Selection.Value = AA.Value
        
        
        A = E
    
    
       Do Until E - 10 = 2
                      
        I = ws.Range(Cells(2, "A")).Row
                      
       
        Set CC = PA.ws.Range(Cells(G, "A"), Cells(I, "A")
                      
        
        D = E - 10
        
        
        Set R1 = PA.ws.Range(Cells(G, "A")).Row
        
            For Each R1 In CC
            
        
            H = PA.ws.Range(Cells(E, "A")).Row
            
            BB = PA.ws.Range(Cells(G, "A"), Cells(I, "A"))
                    
           
            
                Set R2 = PA.ws.Range(Cells(G, "A")).Row
            
                For Each R2 In BB
        
                B = PA.ws.Range(Cells(D, "E").Value - PA.ws.Range(Cells(G, "E")).Value) / PA.ws.Range(Cells(D, "A").Value - PA.ws.Range(Cells(G, "A")).Value)
    
                C = PA.ws.Range(Cells(D, "A"), Cells(G, "A")).Rows.Count
                
                I = PA.ws.Range(Cells(D, "E").Value - PA.ws.Range(Cells(G, "E")).Value)
        
                F = A - (A - H)
            
                J = PA.ws.Range(Cells(H, "A").Value - Cells(G, "A").Value).Rows.Count
            
        
                If PA.ws.Range.Cells(H, "E").Value > AA.Value + (B * F) And F < C + 10 Then
      
            
                ElseIf PA.ws.Range.Cells(H, "E").Value > AA.Value + (B * F) And F > C + 10 Then
                
                TA.ws.Range("A1").End(xlDown).Offset(1, 0).Select
                Selection.Value = "ACTIVE"
                
                PA.ws.Range.Cells(H, "A").Value.Copy
                TA.ws.Range("A1").End(xlDown).Offset(0, 1).Select
                Selection.Paste PasteSpecial:=xlValues
                
                AA.Value.Copy
                TA.ws.Range("A1").End(xlDown).Offset(0, 2).Select
                Selection.Paste PasteSpecial:=xlValues
                
                PA.ws.Range.Cells(D, "A").Value.Copy
                TA.ws.Range("A1").End(xlDown).Offset(0, 3).Select
                Selection.Paste PasteSpecial:=xlValues
                
                PA.ws.Range.Cells(D, "E").Value.Copy
                TA.ws.Range("A1").End(xlDown).Offset(0, 4).Select
                Selection.Paste PasteSpecial:=xlValues
                
                TA.ws.Range("A1").End(xlDown).Offset(0, 5).Value = C
                
                TA.ws.Range("A1").End(xlDown).Offset(0, 6).Value = I
                
                TA.ws.Range("A1").End(xlDown).Offset(0, 7).Value = B
                
                TA.ws.Range("A1").End(xlDown).Offset(0, 8).Select
                Selection.Paste PasteSpecial:=xlValues
                PA.ws.Range.Cells(H, "A").Value.Copy
                TA.ws.Range("A1").End(xlDown).Offset(0, 9).Select
                Selection.Paste PasteSpecial:=xlValues
               
                ElseIf PA.ws.Range.Cells(H, "E").Value < AA.Value + (B * F) Then
                
                End If
                
                Next R2
    
        Next R1
        
        E = E - 1
        
  Loop
        
        Else
            A = A - 1
        End If
    
  Loop
        
        
  Next ws


  End Sub
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Was that the only error in the code?
 
Upvote 0
Not by a long shot, but I have been starting new threads when their is sufficient variation in the nature of the error.
 
Upvote 0

Forum statistics

Threads
1,224,825
Messages
6,181,190
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top