Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 90280

Combining two macros into one **note** these are scraps from recorded macros [on hold]

$
0
0
Sub RemoveDuplicates()
Dim rngData As Range
Dim iCounter As Integer


Sheets("BBT").Select
Set rngData = Range("A1:A5000")
For Each cCell In rngData
    If Not (IsEmpty(cCell.Value) Or Trim(cCell.Value) = "") Then
        For iCounter = cCell.Row + 1 To rngData.Rows.Count
            If cCell.Value = rngData(iCounter).Value Then rngData(iCounter).Value = ""
        Next
    End If
Next

Sheets("DRESS").Select
Set rngData = Range("A1:A5000")
For Each cCell In rngData
    If Not (IsEmpty(cCell.Value) Or Trim(cCell.Value) = "") Then
        For iCounter = cCell.Row + 1 To rngData.Rows.Count
            If cCell.Value = rngData(iCounter).Value Then rngData(iCounter).Value = ""
        Next
    End If
Next

Sheets("PANTS").Select
Set rngData = Range("A1:A5000")
For Each cCell In rngData
    If Not (IsEmpty(cCell.Value) Or Trim(cCell.Value) = "") Then
        For iCounter = cCell.Row + 1 To rngData.Rows.Count
            If cCell.Value = rngData(iCounter).Value Then rngData(iCounter).Value = ""
        Next
    End If
Next
Sheets("SKIRT").Select
Set rngData = Range("A1:A5000")
For Each cCell In rngData
    If Not (IsEmpty(cCell.Value) Or Trim(cCell.Value) = "") Then
        For iCounter = cCell.Row + 1 To rngData.Rows.Count
            If cCell.Value = rngData(iCounter).Value Then rngData(iCounter).Value = ""
        Next
    End If
Next

End Sub

This code will go through these specific sheets and execute the code that will delete the duplicates of the STOCK NO.

Sub RemoveDups_2()

Application.ScreenUpdating = False Dim wsR, wsO As Excel.Worksheet Dim xRow, ouTputRow1, outpUtRow2, toTalQuanTity As Variant Dim dupCount As Variant

Set wsR = Worksheets(1)

xRow = 2 dupCount = 0 While wsR.Cells(xRow, 1).Value <>""'loop through rows, stop loop if cell contains blank value

tof = False
For ouTputRow1 = xRow - 1 To 1 Step -1 ' mag loop from start of row (row1) hanggang current row
                                        ' para malaman kung nasa listahan sa taas ang sku para makumpara

        If wsR.Cells(ouTputRow1, 2).Value = wsR.Cells(xRow, 2).Value Then
            If wsR.Cells(ouTputRow1, 4).Value = wsR.Cells(xRow, 4).Value Then 'check kung pareho ng size
                tof = True  'result ng paghahanap
                Exit For
            End If
        End If
Next

If tof = True Then ' kung nasa listahan na sya, at pareho ang size
    wsR.Cells(ouTputRow1, 6).Value = wsR.Cells(ouTputRow1, 6).Value + wsR.Cells(xRow, 6).Value ', i-add ang quantity ng current row sa sku na nasa listahan ng current row
    wsR.Rows(xRow & ":"& xRow).Delete Shift:=xlUp 'idedelete ang current row dahil na i-add na sya sa kaparehong sku at size
    dupCount = dupCount + 1
Else
    xRow = xRow + 1 ' kung wala pa sya sa list, mareretain sya at mag move forward ang loop
End If

Wend

info = MsgBox("REMOVING DUPLICATES COMPLETE"& vbNewLine & dupCount & " ROWS DELETED", vbInformation, "TAPOS NA BOSS")

End Sub

This code will delete the EXACT Duplicates of the SKU and SIZE and then will add the QTY, then it will delete the row that the dup was deleted from


Viewing all articles
Browse latest Browse all 90280

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>