Home Excel Macro won't work in different files
Reply: 0

Excel Macro won't work in different files

user2359
1#
user2359 Published in May 20, 2018, 12:00 pm

I have a excel macro that I developed in one file but then when I try to run it on another file of the same format, just different data, I error out. There error I'm getting is Run-time error 424: Object required on the line "If del Is Nothing Then" below.

Columns("C:F").Select
Selection.ClearContents
Range("C2").Select
ActiveCell.FormulaR1C1 = "DES"
Range("C2").Select
Selection.AutoFill Destination:=Range("C2:C100")
Range("C2:C100").Select
Range("D2").Select
ActiveCell.FormulaR1C1 = "=LEFT(RC[-3], FIND("" |"", RC[-3]))"
Range("D2").Select
Selection.AutoFill Destination:=Range("D2:D100")
Range("D2:D100").Select
Range("E2").Select
ActiveCell.FormulaR1C1 = "STK"
Range("E2").Select
Selection.AutoFill Destination:=Range("E2:E100")
Range("E2:E100").Select
Range("F2").Select
ActiveCell.FormulaR1C1 = "SMART/AMEX"
Range("F2").Select
Selection.AutoFill Destination:=Range("F2:F100")
Range("F2:F100").Select
Range("G2").Select
ActiveCell.FormulaR1C1 = "=LEFT(RC[-5], FIND("" %"", RC[-5]))"
Range("G2").Select
Selection.AutoFill Destination:=Range("G2:G100")
Range("G2:G100").Select
Columns("G:G").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Columns("C:C").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Set rng = Intersect(Range("B2:B100"), ActiveSheet.UsedRange)
For Each cell In rng
    If (cell.Value) = "0 %" _
    Then
      If del Is Nothing Then
        Set del = cell
      Else: Set del = Union(del, cell)
      End If
    End If
  Next cell
  On Error Resume Next
  del.EntireRow.Delete
Set rng = Intersect(Range("A2:A100"), ActiveSheet.UsedRange)
    For Each cell In rng
    If (cell.Value) = "CASH | CASH" _
    Then
      If del Is Nothing Then
        Set del = cell
      Else: Set del = Union(del, cell)
      End If
    End If
  Next cell
  On Error Resume Next
  del.EntireRow.Delete

The part that I don't understand is how is can be missing the object "del" in one file but not the other using the same macro.

Any thoughts? TIA

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.33722 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO