VBA Code : Filter selection and then Delete All Rows.

punnipah

Board Regular
Joined
Nov 3, 2021
Messages
134
Office Version
  1. 2019
Platform
  1. Windows
Hi,


I Would like to Select Columns "I" and Filter Select "63259" Only Also delete all Rows.



please Help VBA Code : Filter the Selection.Thank You Very much



ABCDEFGHI
ลำดับ (No.)เลขที่รายการ (Transaction ID)เลขที่รายการของร้านค้า (Merchant Transaction ID)วัน – เวลา (Date-Time)รหัสลูกค้า (Customer ID)จำนวนเงิน (Transacted value)สถานะ (Transaction status)การปรับปรุงรายการ (Modified transaction)สาขา (Branch)
172584336815039029_11/5/2022 10:095299SUCCESSNORMAL1137
272584418475038902_11/5/2022 10:162490SUCCESSNORMAL63259
372584419555039047_11/5/2022 10:164590SUCCESSNORMAL63259
472584432085039053_11/5/2022 10:1720500SUCCESSNORMAL1220
572584438415039057_11/5/2022 10:1737900SUCCESSNORMAL1204
672584448685039052_11/5/2022 10:1812900SUCCESSNORMAL1171
772584501195039078_11/5/2022 10:225990SUCCESSNORMAL1137
872584600285039063_11/5/2022 10:304990SUCCESSNORMAL63259
972584801585039173_11/5/2022 10:4628900SUCCESSNORMAL1220
1072585066145039247_11/5/2022 11:0812900SUCCESSNORMAL1224
1172585124665039254_11/5/2022 11:137024SUCCESSNORMAL1206
1272585135805039268_11/5/2022 11:1310489SUCCESSNORMAL1229
1372585142355039280_11/5/2022 11:145299SUCCESSNORMAL1155
1472585147955039269_11/5/2022 11:144989SUCCESSNORMAL1210
1572585152865039266_11/5/2022 11:154489SUCCESSNORMAL1204
1672585160115039282_11/5/2022 11:158900SUCCESSNORMAL1213
1772585178495039241_11/5/2022 11:173429SUCCESSNORMAL63259
1872585243595039315_11/5/2022 11:229499SUCCESSNORMAL1157
1972585251665039316_11/5/2022 11:238900SUCCESSNORMAL1136
2072585254005039233_11/5/2022 11:232845SUCCESSNORMAL63259






The desired result : In The Below



ABCDEFGHI
ลำดับ (No.)เลขที่รายการ (Transaction ID)เลขที่รายการของร้านค้า (Merchant Transaction ID)วัน – เวลา (Date-Time)รหัสลูกค้า (Customer ID)จำนวนเงิน (Transacted value)สถานะ (Transaction status)การปรับปรุงรายการ (Modified transaction)สาขา (Branch)
272584418475038902_11/5/2022 10:162490SUCCESSNORMAL63259
372584419555039047_11/5/2022 10:164590SUCCESSNORMAL63259
872584600285039063_11/5/2022 10:304990SUCCESSNORMAL63259
1772585178495039241_11/5/2022 11:173429SUCCESSNORMAL63259
2072585254005039233_11/5/2022 11:232845SUCCESSNORMAL63259
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Hi

Perhaps:
VBA Code:
Sub foo()
    Dim lngLastRow          As Long
    Dim rngFilter           As Excel.Range
    
    Const strCriteria       As String = "63259" '<-- you can change your filter criteria here
    
    With Sheets("Sheet1") '<-- needs to reference your sheet name
        lngLastRow = .Cells(.Rows.Count, "I").End(xlUp).Row
        Set rngFilter = .Range("I1:I" & lngLastRow)
    End With
    
    With rngFilter
        Call .AutoFilter(Field:=1, Criteria1:="<>" & strCriteria)
        .Offset(1).SpecialCells(xlCellTypeVisible).EntireRow.Interior.ColorIndex = 3
        'Call .Offset(1).SpecialCells(xlCellTypeVisible).EntireRow.Delete '<-- This code will delete the other stuff
        Call .AutoFilter
    End With
    
End Sub

This code highlights the rows to delete in red. Use that to test it first. If it works then you can uncomment the line of code that does the delete.

Hope this helps.
 
Upvote 0

Forum statistics

Threads
1,214,422
Messages
6,119,396
Members
448,891
Latest member
tpierce

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top