Hi Experts
How would you make the current macro delete on extra row......in addtion to its current functionality..
here is the VBA Code:
Private Sub CommandButton1_Click()
Dim ws As Worksheet
Dim Sheet As New Collection
Dim rng As Range
Dim Finished As Boolean
Dim lastfound As Long
Dim rngRow As Long
Dim confirm As Boolean
Dim firstSupplierRow As Range
Dim lastSupplierRow As Range
Dim aSupplier As Range
Dim foundDemand As Boolean
confirm = MsgBox("ARE YOU SURE YOU WANT TO DELETE SUPPLIER :> " & Me.Controls("combobox1").T
ext, vbYesNo, "Delete Supplier") = vbYes
If confirm Then
'Populate affected worksheets
Sheet.Add ThisWorkbook.Worksheets("D
eal Selection")
Sheet.Add ThisWorkbook.Worksheets("T
ables")
Sheet.Add ThisWorkbook.Worksheets("A
lloc (sc.1)")
Sheet.Add ThisWorkbook.Worksheets("A
lloc (sc.2)")
Sheet.Add ThisWorkbook.Worksheets("A
lloc (sc.3)")
Sheet.Add ThisWorkbook.Worksheets("M
odelling (Vol)")
Sheet.Add ThisWorkbook.Worksheets("A
llocation (Vol)")
Sheet.Add ThisWorkbook.Worksheets("C
ashFlow Yearly")
Sheet.Add ThisWorkbook.Worksheets("C
ashFlow Q4")
For Each ws In Sheet
If ws.Name = "Deal Selection" Then
Set rng = ws.Range("B:B").Find(Me.Co
ntrols("co
mbobox1").
Text)
rng.Resize(1, 6).Delete xlShiftUp
ElseIf ws.Name = "Tables" Then
Set rng = ws.Range("J:J").Find(Me.Co
ntrols("co
mbobox1").
Text)
rng.Delete xlShiftUp
ElseIf ws.Name = "CashFlow Q4" Then
Set rng = ws.Range("B:B").Find(Me.Co
ntrols("co
mbobox1").
Text)
lastfound = 1
Finished = False
Do While Not rng Is Nothing And Not Finished
rngRow = rng.Row
lastfound = rng.Row
Do While ws.Range("B" & rngRow) = Me.Controls("combobox1").T
ext
ws.Range("B" & rngRow).EntireRow.Delete
Loop
ws.Range("B" & rngRow).EntireRow.Delete
' Delete this instance
' rng.EntireRow.Delete
Set rng = ws.Range("B:B").Find(Me.Co
ntrols("co
mbobox1").
Text)
Finished = rng Is Nothing
Loop
ws.Range("B" & ws.Rows.Count).End(xlUp).R
esize(1, 52).Borders(xlBottom).Weig
ht = xlMedium
ws.Range("B" & ws.Rows.Count).End(xlUp).B
orders(xlB
ottom).Lin
eStyle = xlContinuous
Else
Set rng = ws.Range("B:B").Find(Me.Co
ntrols("co
mbobox1").
Text)
lastfound = 1
Finished = False
Do While Not rng Is Nothing And Not Finished
rngRow = rng.Row
lastfound = rng.Row
Do While ws.Range("B" & rngRow) = Me.Controls("combobox1").T
ext
ws.Range("B" & rngRow).EntireRow.Delete
Loop
' Delete this instance
' rng.EntireRow.Delete
Set rng = ws.Range("B:B").Find(Me.Co
ntrols("co
mbobox1").
Text)
Finished = rng Is Nothing
Loop
ws.Range("B" & ws.Rows.Count).End(xlUp).R
esize(1, 52).Borders(xlBottom).Weig
ht = xlMedium
ws.Range("B" & ws.Rows.Count).End(xlUp).B
orders(xlB
ottom).Lin
eStyle = xlContinuous
End If
Next
Else
MsgBox Me.Controls("combobox1").T
ext & " - CUSTOMER NOT ADDED", , "USER CANCEL"
End If
Unload Me
End Sub
Start Free Trial