+ Reply to Thread
Results 1 to 6 of 6

Delete a searched range

Hybrid View

  1. #1
    Registered User
    Join Date
    09-23-2004
    Posts
    65

    Exclamation Delete a searched range

    I search first my range of rows, then I want to delete all the rows

    Sub DeleteAll()

    Dim firstCAP As Range
    Dim lastCAP As Range

    'set START DATA_collect
    Sheets("DATA_collect").Activate
    Range("N6").Activate 'start search here at DATA_collect
    firstCAP = ActiveCell.Rows
    'goto first cell that is empty
    Do While Not IsEmpty(ActiveCell)
    ActiveCell.Offset(1, 0).Activate
    Loop
    ActiveCell.Offset(-1, 0).Activate
    lastCAP = ActiveCell.Rows

    Rows("firstCAP:lastCAP").Select
    Selection.Delete Shift:=xlUp


    End Sub

    I get a 'Run time error 91'
    Object variable or with block variable not set.

    Where can I change the code in order to get it work?

  2. #2
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834
    Hi

    have tried
    Dim firstCAP As Long
    Dim lastCAP As Long

    Activecell.Row

    not Rows


    rgds,
    jindon
    Last edited by jindon; 01-27-2005 at 03:09 AM.

  3. #3
    Registered User
    Join Date
    09-23-2004
    Posts
    65
    Yes, I tried it...then I get the Un Time Error 13:Type Mismatch

    This on the line: Rows("firstCAP:lastCAP").Select


    I do not understand the error, normally it has to work with the .Row

  4. #4
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834
    Hi

    could be

    Rows(firstCAP & ":" & lastCAP).Select

    variables shold be Long

    jindon

  5. #5
    Registered User
    Join Date
    09-23-2004
    Posts
    65
    Jindon, thx!

    My nightmare is over!


    I would like to know why only the ":" needs to be with ", not the entire range...is this evident?

  6. #6
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834
    Hi

    Because they are the variavles that you declaired in the dim statement.

    rgds
    jindon

+ 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