-2

I found the following macro online. I would like to know how to add an input box that allow me to tell the macro to check other column than A and to start at other cells than A1.

Sub Check_URLs()

    Dim cell As Range
    Dim IE As Object

    Set IE = CreateObject("InternetExplorer.Application")
    IE.Visible = True

    For Each cell In Range("A1", Range("A" & Rows.Count).End(xlUp))

        If Left(cell.Value, 4) = "http" Then

            ' Goto web page
            IE.Navigate cell.Text

            Application.StatusBar = cell.Text & "  is loading. Please wait..."

            ' Wait until web page is loaded
            Do Until IE.ReadyState = 4 'READYSTATE_COMPLETE
            Loop

            Application.StatusBar = ""

            ' Look for text on web page
            If InStr(IE.Document.body.innerText, _
               "HTTP 404") > 0 Then
               cell.Offset(, 1).Value = "zzz"
               Else
               cell.Offset(, 1).Value = "Y"

            End If
        End If
    Next cell

    IE.Quit
    Set IE = Nothing

End Sub
Alex Knauth
  • 8,133
  • 2
  • 16
  • 31
Oren R
  • 1
  • 1

1 Answers1

0

Go here to learn about the InputBox. Then bookmark that resource as it includes link to the full Excel Object Model (and other office applications, as well), for future reference :)

Application.InputBox Method (Excel)

From which you can then create your InputBox and assign its result to a Range object:

Dim startRange as Range

Set startRange = Application.InputBox(Prompt:="Select starting cell...", _
                                      Default:="$A$1", _
                                      Type:=8)

Then, go here to learn how to find the "last row" in a given range/column/etc.

Error in finding last used cell in VBA

Finally, adjust your For each cell... loop, accordingly.

Alternatively use a simple input box (this will most likely require additional error-handling e.g., what if someone inputs Steve?, or a number instead of a letter, etc.)

Dim myColumnLetter as String
myColumnLetter = Application.InputBox("Input a column letter.", Default:="A")

' ### Here you may want to validate the input value, 
'     since it could cause errors if it's not a valid input
' ###

For Each cell In Range(myColumnLetter & "1", Range(myColumnLetter & Rows.Count).End(xlUp))
Community
  • 1
  • 1
David Zemens
  • 53,033
  • 11
  • 81
  • 130