0% found this document useful (0 votes)
11 views2 pages

Macro

macro excel

Uploaded by

Santiago
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views2 pages

Macro

macro excel

Uploaded by

Santiago
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

Sub Delete_Rows_Based_On_Value()

'Apply a filter to a Range and delete visible rows


'Source: https://www.excelcampus.com/vba/delete-rows-cell-values/

Dim ws As Worksheet
Dim hoj As Worksheet

Dim c As Range

'Set reference to the sheet in the workbook.


Sheets.Add.Name = "SheetCompare"
Set ws = ThisWorkbook.Worksheets("free host and ip")
Set hoj = ThisWorkbook.Worksheets("free_l7_info")
Set blank = ThisWorkbook.Worksheets("SheetCompare")
ws.Activate 'not required but allows user to view sheet if warning message
appears
hoj.Activate

ws.Range("B1:B400").Copy Destination:=blank.Range("a2")
'hoj.Range("B:B").Select
hoj.Range("B2:B400").Copy Destination:=blank.Range("a500")
blank.Range("a1") = "IP"
blank.Range("b1") = "IP_approved"
'Clear any existing filters
On Error Resume Next
ws.ShowAllData
On Error GoTo 0

'1. Apply Filter


blank.Range("A:A").AutoFilter Field:=1, Criteria1:=Array("IPs o host
relacionados", "URL relacionadas", ""), _
Operator:=xlFilterValues

'2. Delete Rows


Application.DisplayAlerts = False
blank.Range("A:A").SpecialCells(xlCellTypeVisible).Delete
Application.DisplayAlerts = True

'3. Clear Filter


On Error Resume Next
ws.ShowAllData
On Error GoTo 0

Workbooks("URLfree.xlsx").Worksheets("URL GRATIS").Range("A5:A500").Copy _
Workbooks("IPcompare.xlsm").Worksheets("SheetCompare").Range("B1")

blank.Range("A:A").Columns.AutoFit
blank.Range("B:B").Columns.AutoFit

For Each c In blank.Range("A1:A600")


c = Replace(c, "/*", "")
c = Application.Trim(c)
Next

For Each c In blank.Range("B1:B400")


c = Application.Trim(c)
Next

You might also like