Question re. Custom Function (UDF)

JumboCactuar

Well-known Member
Joined
Nov 16, 2016
Messages
788
Office Version
  1. 365
Platform
  1. Windows
Hi,
I have this custom UDF and want to use it as a formula to fill a column..

Would this be volatile and recalculate on every cell change?

VBA Code:
Function URLExists(url As String) As Boolean
    Dim Request As Object
    Dim ff As Integer
    Dim rc As Variant
  
    On Error GoTo EndNow
    Set Request = CreateObject("WinHttp.WinHttpRequest.5.1")
  
    With Request
      .Open "GET", url, False
      .Send
      rc = .StatusText
    End With
    Set Request = Nothing
    If rc = "OK" Then URLExists = True
  
    Exit Function
EndNow:
End Function

B2 filled down =
Excel Formula:
=URLExists(A2)

Would i be better running a macro and writing the values? Or would it be fine to use as a formula

Thanks for any info
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
I would never use a function that was going to make a call to a remote URL on every recalculation that is is recipe for making your workbook really really slow.
Just once when the workbook is activated should be good enough. URL don't usually disappear very often
Or even run on demand i.e in a subroutine
 
Upvote 0
I would never use a function that was going to make a call to a remote URL on every recalculation that is is recipe for making your workbook really really slow.
Just once when the workbook is activated should be good enough. URL don't usually disappear very often
Or even run on demand i.e in a subroutine

Thanks
I will have a sub that loops the row and calls the function on request.
That should be ok i think

VBA Code:
Sub CheckURLS()

LR = Cells(Rows.Count, 1).End(xlUp).Row

For i = 2 To LR
    Cells(i, 2) = URLExists(Cells(i, 2))
Next

End Sub
 
Upvote 0
Might want to consider putting it all into 1 subroutine. If you call that function for each cell in your range, you will be creating a new object for each cell.

Doing it like this might speed things up.

VBA Code:
Sub MAIN()
    Dim Request As Object: Set Request = CreateObject("WinHttp.WinHttpRequest.5.1")
    Dim r As Range: Set r = Range("A1:A" & Range("A" & Rows.Count).End(xlUp).Row)
    Dim AR() As Variant: AR = r.Value2
    Dim b As Boolean
    On Error GoTo EndNow
    
    For i = 1 To UBound(AR)
    b = True
        With Request
          .Open "GET", AR(i, 1), False
          .Send
          If b Then AR(i, 1) = True
        End With
    Next i
    
    Set Request = Nothing
    r.Offset(, 1).Value = AR
    Exit Sub
    
EndNow:
        AR(i, 1) = False
        b = False
        Resume Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,825
Messages
6,181,191
Members
453,021
Latest member
pingpong7117

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