Delete an Entire Row in .vbs

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Tuanisviet
    New Member
    • Jan 2007
    • 37

    Delete an Entire Row in .vbs

    I'm hoping this is the right sub-forum to post this question, my apologies if it's not.


    The problem I'm having is that I can't get a blank row to be deleted. Below is a section of code where the Selection.Entir eRow.Delete should occur.

    '-- Loop through to make sure only MS Patches are there. Delete Empty rows
    For row = 2 To allRows
    allString = xlSReport.Cells (row,2)
    If (allString = "") Then
    allString.Entir eRow.Delete
    End If
    'Do Nothing
    Next
    xlSReport.colum ns(1).Autofit()
    xlSReport.colum ns(2).Autofit()
    xlSReport.colum ns(4).Autofit()
    xlSReport.colum ns(5).Autofit()
  • Stewart Ross
    Recognized Expert Moderator Specialist
    • Feb 2008
    • 2545

    #2
    What type is your variable AllString? It looks like it should be a Range object, but if it is you are not using the object Set keyword to set it to the range defined by Cells(row, 2) in your FOR loop - which would normally cause a compiler error.

    If it is a string, then you cannot use that string as a range object to delete the row inside your IF - and again, trying to do so should throw up a compiler error.

    I guess you might have used an untyped variant for AllString - but if you have this will not work either. The EntireRow.Delet e method is a property of a range object, and this is what you must supply if you expect it to work.

    One way or the other you seem to be using an incorrect type here.

    -Stewart

    Comment

    Working...