Consulting

Results 1 to 4 of 4

Thread: Solved: How to Delete Data on the other sheet using VBA?

  1. #1

    Solved: How to Delete Data on the other sheet using VBA?

    I have a VBA code for deleting data:
    Sub DeleteData()
    Dim LR As Long
    LR = Range("J" & Rows.Count).End(xlUp).Row
      On Error Resume Next
      Range("J4:J" & LR).SpecialCells(xlBlanks, xlTextValues).EntireRow.Delete
      On Error GoTo 0
    End Sub
    But this code deletes blank rows on this sheet.

    What if I want to delete the data on the other sheet?

    I tried modifying the formula but this doesn't work.
    Sub DeleteData()
    Dim LR As Long
    Sheets("sheet2").LR = Range("J" & Rows.Count).End(xlUp).Row
      On Error Resume Next
      Range("J4:J" & LR).SpecialCells(xlBlanks, xlTextValues).EntireRow.Delete
      On Error GoTo 0
    End Sub
    Please help.

  2. #2
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,064
    Location
    Are you trying to delete column J on sheet 2? and what triggers this event?
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  3. #3
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    You have to make a reference to the other sheet whenever you deal with a range
    [VBA]Sub DeleteData()
    Dim LR As Long
    With Sheets("sheet2")
    LR = .Range("J" & Rows.Count).End(xlUp).Row
    On Error Resume Next
    .Range("J4:J" & LR).SpecialCells(xlBlanks, xlTextValues).EntireRow.Delete
    On Error GoTo 0
    End With
    End Sub[/VBA]
    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
    Thanks mdmckillop! By doing this I also resolved my other issue "How to combine multiple codes in 1 sheet"!

    Thanks a million! I hope you'll not go tired of helping people like me!

Posting Permissions

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