Help with using "find" or something else Arrays?

ShogunStealth

New Member
Joined
Nov 6, 2021
Messages
23
Office Version
  1. 2019
Platform
  1. Windows
I have a large spreadsheet with more that 400K rows of data on Sheet(1) with several columns but one column H contains URLs. I can copy the URLs to a another sheet in the same book (Sheet(2) = "UniqueURL") in column A and only display unique URL in alphabetical order (with heading). I then expect the user to view this sheet and list of URL and place a value in column B like "Keep" next to the URLs they wish to keep. I cannot think of a better ways of capturing the user selections for a list that can be more than 300 options. The selections may be one or several websites. I am struggling to write some vba code that will allow me to then delete all and entire row of data and remove the blanks on Sheet(1) that don't match the "keep" URLs. So that only the rows of data selected remains without any gaps based on the selection on Sheet(2). The matching should be on whole cell not partial. For example;

Sheet(2)
http://fruit.com.au/SummerFruit/ Keep
http://fruit.com.au/SummerFruit/Citrus/Madarin/ Keep
http://fruit.com.au/SummerFruit/Mangoes/
http://fruit.com.au/SummerFruit/Watermelon/ Keep

Selecting http://Fruit.com.au/SummerFruit/ does not automatically include subsites not selected like http://Fruit.com.au/SummerFruit/Citrus/ unless selected (like http://Fruit.com.au/SummerFruit/Citrus/Madarin/ ) or http://Fruit.com.au/SummerFruit/Mangoes/

I have never used arrarys before so I'm a bit lost but vaguely understand indexing a variable with multiple values. I would prefer to perhaps use a "find" somehow. Also, because there are so many rows I need some efficient code that runs quickly. Appreciate any help our thoughts.
 
This the piece of code comparing values between 2 worksheets via an object in virtual member that work for me from Alex, it includes the amendment that he also posted in a later revision. This work belong to Alex.

VBA Code:
Sub Compare()

Dim LastRowSheet1 As Long
Dim LastRowSheet2 As Long
Dim i As Long
Dim j As Long
Dim wsMain As Worksheet
Dim wsURL As Worksheet
Dim arrMain As Variant
Dim arrURL As Variant
Dim dictURL As Object

Set wsMain = Worksheets(1)
Set wsURL = Worksheets(2)

wsMain.Columns("H:H").Insert Shift:=xlToRight

LastRowSheet1 = wsMain.Cells(Rows.Count, 1).End(xlUp).Row  ' This value can be well over 400,000
LastRowSheet2 = wsURL.Cells(Rows.Count, 1).End(xlUp).Row ' This value can be upto 1,000

With wsMain
arrMain = .Range(.Cells(2, 7), .Cells(LastRowSheet1, 8)).Value
End With
   
With wsURL
arrURL = .Range(.Cells(2, 1), .Cells(LastRowSheet2, 1)).Value
End With
   
' Load URLs into dictionary
Set dictURL = CreateObject("scripting.dictionary")
    If IsArray(arrURL) Then
        For i = 1 To UBound(arrURL)
            dictURL(arrURL(i, 1)) = i
        Next i
    Else
        dictURL(arrURL) = 1
    End If
   
' Flag if value exists in dict
For j = 1 To UBound(arrMain)
If dictURL.exists(arrMain(j, 1)) Then arrMain(j, 2) = "Keep"
Next j
   
' Write out results to sheet
With wsMain
.Range(.Cells(2, 8), .Cells(LastRowSheet1, 8)).Value = Application.Index(arrMain, 0, 2)
End With

End Sub
 
Upvote 0

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.

Forum statistics

Threads
1,223,886
Messages
6,175,196
Members
452,616
Latest member
intern444

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