Run-time error 5 - Invalid procedure call or argument

PGNewbie

New Member
Joined
Feb 6, 2020
Messages
41
Office Version
  1. 365
Platform
  1. Windows
I'm getting the mention error when trying to compare a value in my selected row. I'm not sure how to tackle this error.

VBA Code:
Sub CompareColoumns()
Dim d As Range
    Dim c As Range
    Dim j As Integer
    Dim Source As Worksheet
    Dim Target As Worksheet
    Dim Condition As Worksheet
    Dim lastrow2 As Long
    
    

    Set Source = ActiveWorkbook.Worksheets("Input")
    Set Condition = ActiveWorkbook.Worksheets("Top10NoisiestDevices")
    
    
    'This will start copying data to Target sheet at row 3
    
        
    For Each d In Condition.Range("A2:A11") 'specifiy condition
      
    'create worksheet for each value in condition
      
    Set Target = Sheets.Add(after:=ActiveSheet)
      
    Target.Name = "Device-" & d.Value
    
      
    'add code to show client name on line A1
    
    Target.Range("A1").Value = d.Offset(, 4).Value
    Target.Range("A1:L1").Merge
    Target.Range("A1").Interior.ColorIndex = 45
        
        
        
    'Sheets("Input").Range("A1:AE1").Copy Target.Range("A2")
    
    [A2:L2] = Split("Start_Time Host_Name Client_Name Message Count Probe Source Origin Status End_Time Ack_By Ticket")
    Target.Range("A2:L2").Interior.ColorIndex = 44
            
    'lastrow2 = Target.Cells(Target.Rows.Count, "A").End(xlUp).Row
    
  
      
        For Each c In Source.Range("K2:K6893")
            
        lastrow2 = Target.Cells(Target.Rows.Count, "A").End(xlUp).Row
        
            'If c.Value = d.Value Then
            If c.Value = d.Value And c(c.Offset(, 12)).Value = d(d.Offset(, 2)).Value Then '<-- causes errror
          
                  
                    Source1.Cells(c.Row, 5).Copy Target.Cells(lastrow2 + 1, 1)
                    Source1.Cells(c.Row, 11).Copy Target.Cells(lastrow2 + 1, 2)
                    Source1.Cells(c.Row, 22).Copy Target.Cells(lastrow2 + 1, 3)
                    Source1.Cells(c.Row, 6).Copy Target.Cells(lastrow2 + 1, 4)
                    Source1.Cells(c.Row, 8).Copy Target.Cells(lastrow2 + 1, 5)
                    Source1.Cells(c.Row, 17).Copy Target.Cells(lastrow2 + 1, 6)
                    Source1.Cells(c.Row, 12).Copy Target.Cells(lastrow2 + 1, 7)
                    Source1.Cells(c.Row, 13).Copy Target.Cells(lastrow2 + 1, 8)
                    Source1.Cells(c.Row, 3).Copy Target.Cells(lastrow2 + 1, 9)
                    Source1.Cells(c.Row, 4).Copy Target.Cells(lastrow2 + 1, 10)
                    Source1.Cells(c.Row, 21).Copy Target.Cells(lastrow2 + 1, 11)
                    Source1.Cells(c.Row, 28).Copy Target.Cells(lastrow2 + 1, 12)
            
                
            End If
              
        Next c
    Rows("3:3").Select
    ActiveWindow.FreezePanes = True
    Range("A1").Select
    'Zoom to first cell
    ActiveWindow.ScrollRow = 1
    ActiveWindow.ScrollColumn = 1

    Next d
End Sub
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
How about
VBA Code:
If c.Value = d.Value And c.Offset(, 12).Value = d.Offset(, 2).Value Then
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,325
Members
452,635
Latest member
laura12345

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