• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

If sheet5 has Sheet7 data then delete that data

yes vletm sir it will paste the data many times in sheet7
What about this then?
I gave you an example, when you transfer data to sheet 7, the data in sheet 5 is deleted. You did't wanted it, and now you are asking for it. I am lost.
 
Belleke this question is different from that
That question was different
Actually i will run the code twice or thrice or n no. Of times with different data so i dont want to mix up with each result
Plz look into this question
Everything is going perfect ur code and my problems
 
Leonardo1234
You way seems to be one step forward > one step right > two steps left > three steps backward > two steps right > and so on ...
Instead of stepping forward ...

Do You have a master plan for Your copy & paste & move & add & delete & compare ... cases?

It would be possible to get clearer code
if no need to change basic same code many time.

And for You, it would be much easier to use these ...
 
Code:
Option Explicit

Sub DeleteSheet5Data()
    Dim ws5 As Worksheet, ws7 As Worksheet
    Dim rw5 As Long, rw5Max As Long, col5 As Integer, col5Max As Integer
    Dim rw7 As Long, rw7Max As Long, col7 As Integer, col7Max As Integer
    Dim ar5 As Variant, ar7 As Variant
    Dim bHas7Data As Boolean
   
    Application.ScreenUpdating = False
   
    Set ws5 = ThisWorkbook.Worksheets("Sheet5")
    Set ws7 = ThisWorkbook.Worksheets("Sheet7")
    rw5Max = ws5.Range("A1048576").End(xlUp).Row
    col5Max = ws5.Range("XFD1").End(xlToLeft).Column
    rw7Max = ws7.Range("A1048576").End(xlUp).Row
    col7Max = ws7.Range("XFD1").End(xlToLeft).Column
    ws5.Activate
    ar5 = ws5.Range(Cells(1, col5Max + 1), Cells(rw5Max, col5Max + 1))
    ws7.Activate
    ar7 = ws7.Range(Cells(1, col7Max + 1), Cells(rw7Max, col7Max + 1))
    For rw7 = 1 To rw7Max
        For col7 = 1 To col7Max
            If col7 = 1 Then
                ar7(rw7, 1) = ws7.Cells(rw7, col7)
            Else
                ar7(rw7, 1) = ar7(rw7, 1) & "|" & ws7.Cells(rw7, col7)
            End If
        Next col7
    Next rw7
    For rw5 = 1 To rw5Max
        For col5 = 1 To col5Max
            If col5 = 1 Then
                ar5(rw5, 1) = ws5.Cells(rw5, col5)
            Else
                ar5(rw5, 1) = ar5(rw5, 1) & "|" & ws5.Cells(rw5, col5)
            End If
        Next col5
        bHas7Data = False
        For rw7 = 1 To rw7Max
            If ar7(rw7, 1) = ar5(rw5, 1) Then
                bHas7Data = True
                Exit For
            End If
        Next rw7
        If bHas7Data Then
            ar5(rw5, 1) = 1
        Else
            ar5(rw5, 1) = 0
        End If
    Next rw5
    ws5.Activate
    ws5.Range(Cells(1, col5Max + 1), Cells(rw5Max, col5Max + 1)) = ar5
    ws5.Sort.SortFields.Clear
    ws5.Sort.SortFields.Add Key:=Range(Cells(1, col5Max + 1), Cells(rw5Max, col5Max + 1)), _
        SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    With ws5.Sort
        .SetRange Range(Cells(1, 1), Cells(rw5Max, col5Max + 1))
        .Header = xlNo
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
    For rw5 = 1 To rw5Max
        If ws5.Cells(rw5, col5Max + 1) = 1 Then
            Exit For
        End If
    Next rw5
    ws5.Range(Cells(rw5, 1), Cells(rw5Max, 1)).EntireRow.Delete
    ws5.Range(Cells(1, col5Max + 1), Cells(1, col5Max + 1)).EntireColumn.Delete
End Sub
 
What a disaster code.:eek:
If sheet5 is the active sheet then this is enough. <--important
Code:
Sub belle()
    For j = 1 To Sheets("Sheet7").Cells(Rows.Count, 1).End(xlUp).Row
    For i = Sheets("Sheet5").Cells(Rows.Count, 1).End(xlUp).Row To 1 Step -1
        For ii = 1 To 20
            check1 = check1 & Sheets("Sheet5").Cells(i, ii)
            check2 = check2 & Sheets("Sheet7").Cells(j, ii)
        Next
        If check1 = check2 Then
            Rows(i).Delete
        End If
        check1 = ""
        check2 = ""
    Next
Next
End Sub
 
No problem i will replace the code with ur code thnx for the info Belleke &
Thnx Belleke for giving ur precious time and great support to this post
 
Back
Top