VBA Code to handle error

fari1

Active Member
Joined
May 29, 2011
Messages
362
Code:
i have a loop, which has many subroutines, the loop starts with the web query and bring in data for ticker symbols in my sheet, when a ticker symbol is wrong, then the web query is not distured, as it doesn't give any error, but my sub routines get too much disturbed, my routines contain,trim,copy and other codes, which will only be run if there's data in the sheet, since there's no data so no subroutines and error start arising. below is the dummy URL, just to show u the pic of my scenerio, i've tried using some sort of error handling but of no use, rather it is disturbing my rest of the codes and all the results are getting wrong even for the working symbols as well. the part of the code that is highlighted bold needs to have error handling, also i want to create a log for every sumbol for which error appeared, either highlight the symbol, or the url in the separate sheet. any quick help shall be highly appreciated

Pr
Code:
ivate Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$A$1" Then
Application.ScreenUpdating = False
Set shin = Sheets("info")
Set shti = Sheets("symbols")
With shin
    Range("A21:E200").ClearContents
End With
Dim sts As String
sts = shin.Range("A1").Value
With shin.QueryTables.Add(Connection:= _
"URL;http://www.google.com" _
& sts, Destination:=shin.Range("A1"))
        .Name = sicdata
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .BackgroundQuery = True
        .RefreshStyle = xlOverwriteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .WebSelectionType = xlEntirePage
        .WebFormatting = xlWebFormattingNone
        .WebPreFormattedTextToColumns = True
        .WebConsecutiveDelimitersAsOne = True
        .WebSingleBlockTextImport = False
        .WebDisableDateRecognition = False
        .WebDisableRedirections = False
        .Refresh BackgroundQuery:=False
End With
            On Error Resume Next
            Call test
            If Err.Number = 1004 Then
            On Error GoTo errhandler
            Exit Sub
            
        Else
        
        Call test
        Call loopB
        Call finalurl
        Call findHTTPConvert
        Call faricopy
        Call furl
errhandler:
            Select Case Err.Number
              Case Is = 1004
              Case Else
            End Select
        ActiveWorkbook.Connections("Connection").Delete
        Call RemNamedRanges
       
End If
End If
End Sub
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.

Forum statistics

Threads
1,224,551
Messages
6,179,480
Members
452,915
Latest member
hannnahheileen

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