?
Solved

HOW FIX ERROR 424 VBA

Posted on 2008-10-08
2
Medium Priority
?
1,124 Views
Last Modified: 2013-11-25
Hello

i got the error 424 en VBA/excel ,  and i couldn't understand the error or fix.

The error stop in ..... Is Nothing Then DelRange.EntireRow.Delete

Thanks

Itzel


Sub KillStr()
    Dim Myrange As Range, DelRange As Range, C As Range
    Dim FirstAddress As String
    Dim MyStr, MyElm
    
    Columns("E:E").Select
    Selection.Delete Shift:=xlToLeft
    Columns("F:F").Select
    Selection.Delete Shift:=xlToLeft
    
 
    MyStr = Array("5GFI10", "5MAC20", "INT515", "5MAC15", "5MAC05", "5MAC10", "5TYC10", "5GVW10")
      
    Set Myrange = Intersect(ActiveSheet.UsedRange, Range("b2:b25000"))
    If Myrange Is Nothing Then Exit Sub
    Application.ScreenUpdating = False
 
    For Each MyElm In MyStr
        Set C = Myrange.Find(MyElm, Myrange.Cells(1), xlValues, xlPart)
        If Not C Is Nothing Then
            Set DelRange = C
            FirstAddress = C.Address
            Do
                Set C = Myrange.FindNext(C)
                Set DelRange = Union(DelRange, C)
            Loop While FirstAddress <> C.Address
        End If
        If Not DelRange Is Nothing Then DelRange.EntireRow.Delete
    Next MyElm

Open in new window

0
Comment
Question by:Itzel05
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 50

Accepted Solution

by:
Dave Brett earned 1200 total points
ID: 22669425
This looks like one of mine thta has bene adapted. Try this below - it avoids deleting the range until the end which stops the code short cicuiting if the look at range is deleted mid code

Cheers

Dave
Sub KillStr()
    Dim Myrange As Range, DelRange As Range, C As Range
    Dim FirstAddress As String
    Dim MyStr, MyElm
    
    Columns("E:E").Select
    Selection.Delete Shift:=xlToLeft
    Columns("F:F").Select
    Selection.Delete Shift:=xlToLeft
    
 
    MyStr = Array("5GFI10", "5MAC20", "INT515", "5MAC15", "5MAC05", "5MAC10", "5TYC10", "5GVW10")
      
    Set Myrange = Intersect(ActiveSheet.UsedRange, Range("b2:b25000"))
    If Myrange Is Nothing Then Exit Sub
    Application.ScreenUpdating = False
 
    For Each MyElm In MyStr
        Set C = Myrange.Find(MyElm, Myrange.Cells(1), xlValues, xlPart)
        If Not C Is Nothing Then
            Set DelRange = C
            FirstAddress = C.Address
            Do
                Set C = Myrange.FindNext(C)
                Set DelRange = Union(DelRange, C)
            Loop While FirstAddress <> C.Address
        End If
    Next MyElm
    If Not DelRange Is Nothing Then DelRange.EntireRow.Delete
End Sub

Open in new window

0
 
LVL 59

Assisted Solution

by:Saurabh Singh Teotia
Saurabh Singh Teotia earned 800 total points
ID: 22669437
There you go...use this...

Saurabh...


Sub KillStr()
    Dim Myrange As Range, DelRange As Range, C As Range
    Dim FirstAddress As String
    Dim MyStr, MyElm
    
    Columns("E:E").Select
    Selection.Delete Shift:=xlToLeft
    Columns("F:F").Select
    Selection.Delete Shift:=xlToLeft
    
 
    MyStr = Array("5GFI10", "5MAC20", "INT515", "5MAC15", "5MAC05", "5MAC10", "5TYC10", "5GVW10")
      
    Set Myrange = Intersect(ActiveSheet.UsedRange, Range("b2:b25000"))
    If Myrange Is Nothing Then Exit Sub
    Application.ScreenUpdating = False
 
    For Each MyElm In MyStr
        Set C = Myrange.Find(MyElm, Myrange.Cells(1), xlValues, xlPart)
        If Not C Is Nothing Then
            Set DelRange = C
            FirstAddress = C.Address
            Do
                Set C = Myrange.FindNext(C)
                Set DelRange = Union(DelRange, C)
            Loop While FirstAddress <> C.Address
        End If
        If Not DelRange Is Nothing Then
        DelRange.EntireRow.Delete
       Set DelRange = Nothing
        End If
        
    Next MyElm
End Sub

Open in new window

0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question