Lookup and copy not working

cdfjdk

New Member
Joined
Sep 3, 2014
Messages
31
I have the macro below that works with ordinary text strings, but will not work with the lists of URLs I have. Is this because of special characters?

The code:

  1. Looks up a URL in column B in Sheet2
  2. Finds the matching URL in column B in Sheet1
  3. Copies cells in cols C to D in row in Sheet1 with the matching URL
  4. Pastes the copied cells into adjacent cells in Sheet2
There are almost 8100 URLs in Sheet1 and there are at least some definite matches in Sheet2, but nothing is returned.

As mentioned, the macro works OK with ordinary text strings, so I am puzzled!

Help very gratefully received!
Code:
Sub Get_PDF_pageviews()


Dim cell        As Range
Dim PDF_URL       As Variant
Dim LastRow     As Long
        
    Application.ScreenUpdating = False
    Application.EnableEvents = False
    
    Worksheets("Sheet2").Activate
    
    With Worksheets("Sheet2")
        
        LastRow = .Cells(Rows.Count, "B").End(xlUp).Row
        
        For Each PDF_URL In Sheets("Sheet2").Range("B2:B" & LastRow).Cells
        
            Set cell = Sheets("Sheet1").Range("B:B").Find(PDF_URL, , xlValues, xlWhole, xlByRows, False, False, False)


            If Not cell Is Nothing Then
            
                cell.Offset(, 1).Resize(, 2).Copy Destination:=Worksheets("Sheet2") _
                .Range("B:B").Find(PDF_URL, , xlValues, xlWhole, xlByRows, False, False, False).Offset(, 1)
                
            End If
                       
        Next PDF_URL

    End With
    Application.ScreenUpdating = True
    Application.EnableEvents = True
            
End Sub
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.

Forum statistics

Threads
1,223,894
Messages
6,175,252
Members
452,623
Latest member
Techenthusiast

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