+ Reply to Thread
Results 1 to 3 of 3

Object variable error

  1. #1
    Registered User
    Join Date
    05-06-2004
    Posts
    60

    Object variable error

    Hello,

    Using a macro to delete rows depending on blank cells in column A. At times,all cells in column A are blank and macro fails. Object variable not set error when this occurs. Is there an error statement I can insert to overcome this problem? Something like on error resume next ?

    Thanks !

    Sub DeleteRowsThatLookEmptyinColA()
    Application.ScreenUpdating = False
    Application.Calculation = xlCalculationManual 'pre XL97 xlManual
    Dim Rng As Range, ix As Long
    Set Rng = Intersect(Range("A:A"), ActiveSheet.UsedRange)
    For ix = Rng.Count To 1 Step -1
    If Trim(Replace(Rng.Item(ix).Text, Chr(160), Chr(32))) = "" Then
    Rng.Item(ix).EntireRow.Delete
    End If
    Next
    done:
    Application.Calculation = xlCalculationAutomatic
    End Sub

  2. #2
    K Dales
    Guest

    RE: Object variable error

    Have you tried this:
    Set Rng = Intersect(Range("A:A"), ActiveSheet.UsedRange)
    If Not (Rng is Nothing) Then...
    For ix = Rng.Count To 1 Step -1
    If Trim(Replace(Rng.Item(ix).Text, Chr(160), Chr(32))) = "" Then
    Rng.Item(ix).EntireRow.Delete
    End If
    Next
    End If


    "Oreg" wrote:

    >
    > Hello,
    >
    > Using a macro to delete rows depending on blank cells in column A. At
    > times,all cells in column A are blank and macro fails. Object variable
    > not set error when this occurs. Is there an error statement I can
    > insert to overcome this problem? Something like on error resume next
    > ?
    >
    > Thanks !
    >
    > Sub DeleteRowsThatLookEmptyinColA()
    > Application.ScreenUpdating = False
    > Application.Calculation = xlCalculationManual 'pre XL97 xlManual
    > Dim Rng As Range, ix As Long
    > Set Rng = Intersect(Range("A:A"), ActiveSheet.UsedRange)
    > For ix = Rng.Count To 1 Step -1
    > If Trim(Replace(Rng.Item(ix).Text, Chr(160), Chr(32))) = "" Then
    > Rng.Item(ix).EntireRow.Delete
    > End If
    > Next
    > done:
    > Application.Calculation = xlCalculationAutomatic
    > End Sub
    >
    >
    > --
    > Oreg
    > ------------------------------------------------------------------------
    > Oreg's Profile: http://www.excelforum.com/member.php...fo&userid=9195
    > View this thread: http://www.excelforum.com/showthread...hreadid=380818
    >
    >


  3. #3
    Registered User
    Join Date
    05-06-2004
    Posts
    60
    K Dales ,

    Thanks for the help! That worked perfectly.

    Oreg

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1