Why is this a run time error 1004?

vbaNumpty

Board Regular
Joined
Apr 20, 2021
Messages
160
Office Version
  1. 365
Platform
  1. Windows
The following line gives me 1004 error and I cannot understand why: searchValue.Offset(p, -5).Resize(b, -16).Borders.LineStyle = xlContinuous


Full code:

VBA Code:
Sub imageCompare()

    Dim dashB As Worksheet
    Dim imageB As Worksheet
    
    Dim findValue As Range
    Dim searchValue As Range
    Dim addMe As Range
    Dim formatMe As Range
    Dim ordrList As Range
    Dim myarray As Variant
    
    Dim j As Integer
    Dim i As Integer
    Dim y As Integer
    Dim p As Integer
    Dim n As Integer
    Dim x As Integer
    Dim b As Integer
    Dim u As Integer
    
    Set dashB = Sheet1
    Set imageB = Sheet4
    Set ordrList = Sheet3.Range("outdata")
    
    myarray = ordrList

    i = Evaluate("=COUNTA(Image!X:X)")
    
    x = 0
    
    For j = 1 To i
        'Setting ID# on updated values
        Set findValue = imageB.Range("X:X").Find(What:=myarray(j, 1), _
            LookIn:=xlValues, lookat:=xlWhole)
        'Using to match values to original launched data
        Set searchValue = dashB.Range("X:X").Find(What:=myarray(j, 1), _
            LookIn:=xlValues, lookat:=xlWhole)
            
        'Find Number of Lines
        y = findValue.Offset(0, -3).value
        p = searchValue.Offset(0, -3).value
        
            If y > p Then
                b = y - p
                
                For u = 1 To b 'insert # of new lines in order
                    
                    searchValue.Offset(p, 0).EntireRow.Insert
                       
                Next u
                
                searchValue.Offset(p, -5).Resize(b, -16).Borders.LineStyle = xlContinuous
                
            End If
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
62,265
Office Version
  1. 365
Platform
  1. Windows
You cannot resize with -ve numbers.
 
Solution

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
37,334
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS
You can't use a negative value in Resize (it doesn't work like the OFFSET worksheet function)
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
62,265
Office Version
  1. 365
Platform
  1. Windows
Glad we could help & thanks for the feedback.
 

Forum statistics

Threads
1,141,132
Messages
5,704,458
Members
421,351
Latest member
Sheogorath

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
Top