Consulting

Results 1 to 5 of 5

Thread: macro do not work

  1. #1
    VBAX Mentor
    Joined
    Jun 2005
    Posts
    374
    Location

    macro do not work

    hello
    the following macro can be found in john walkenbach's book
    "excel 2002 vba programming" - page 305.it do not work.

    [VBA]
    Sub deleteEmptyrows()
    Dim row
    Dim LastRow As Long, r As Long
    LastRow = ActiveSheet.UsedRange.Rows.Count
    LastRow = LastRow + ActiveSheet.UsedRange.row - 1
    Application.ScreenUpdating = False
    For r = LastRow To 1 Step -1
    If Application.WorksheetFunction.CountA(row(r)) = 0 Then
    row(r).Delete
    End If
    Next
    End Sub

    [/VBA]
    please help
    thanks
    moshe

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    ARe you sure that you haven't mis-transcribed that Moshe?

    Where you have row(r), try Rows(r) (two places in the code).

  3. #3
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Try Rows(r) instead of row(r)
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  4. #4
    VBAX Expert Dave's Avatar
    Joined
    Mar 2005
    Posts
    835
    Location
    Don't you need to do this in order to see your changes? Dave
    [VBA]
    Application.ScreenUpdating = True
    [/VBA]

  5. #5
    VBAX Tutor CCkfm2000's Avatar
    Joined
    May 2005
    Posts
    209
    Location
    hi lior03,
    here is the code...

    [VBA]Sub deleteEmptyrows()
    Dim row
    Dim LastRow As Long, r As Long
    LastRow = ActiveSheet.UsedRange.Rows.Count
    LastRow = LastRow + ActiveSheet.UsedRange.row - 1
    Application.ScreenUpdating = False
    For r = LastRow To 1 Step -1
    If Application.WorksheetFunction.CountA(Rows(r)) = 0 Then
    Rows(r).Delete
    End If
    Next
    End Sub
    [/VBA]

    regards

    cckfm2000

Posting Permissions

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