+ Reply to Thread
Results 1 to 5 of 5

Case without select case error

  1. #1
    Registered User
    Join Date
    07-25-2007
    Posts
    3

    Case without select case error

    I need some help on my code. It gives me a case without select case error. Can anybody give me some hints on what is wrong?

    For i = 11 To 51
    r = Range("R" & i).Value
    w = Range("M" & i).Value
    Select Case r
    Case Is > w * 1.15
    Range("R" & i).Activate
    With Selection.Interior
    .ColorIndex = 3
    .Pattern = xlSolid
    .PatternColorIndex = xlAutomatic
    Case Is < w * 0.85
    Range("R" & i).Activate
    With Selection.Interior
    .ColorIndex = 4
    .Pattern = xlSolid
    .PatternColorIndex = xlAutomatic
    Case Else
    Range("R" & i).Activate
    With Selection.Interior
    .ColorIndex = 1
    .Pattern = xlSolid
    .PatternColorIndex = xlAutomatic
    End Select
    Next i
    i is an integer, r and w are doubles
    Last edited by Tano; 07-25-2007 at 09:45 AM.

  2. #2
    Forum Contributor SOS's Avatar
    Join Date
    01-26-2004
    Location
    Glasgow, Scotland
    MS-Off Ver
    Excel 2003
    Posts
    327
    Hi Tano,

    You missed out three "End With" statements.

    Your code should read as follows:
    Please Login or Register  to view this content.

    Hope this helps

    Seamus

  3. #3
    Registered User
    Join Date
    07-25-2007
    Posts
    3
    What a stupid mistake. Thanks a lot!

    Do you additionally know why I get a 1004 error on this code sometimes? Debug gives an error on this line .Refresh BackgroundQuery:=False
    I solved it by turning on Option explicit. NO idea why that works though.

    Sub SelectCell()

    Dim darget As Range
    Set darget = Sheets("Blad1").Range("I12")
    Application.ScreenUpdating = False
    For i = 12 To 50
    Call Getprice((Sheets("Blad1").Range("D" & i).Text), darget)
    Set darget = darget.Cells(2, 1)
    Next i
    Sheets("Blad1").Select
    ' Range("F5:F40").Select
    'Selection.Replace What:=".", Replacement:=",", LookAt:=xlPart, _
    ' SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
    ' ReplaceFormat:=False
    ' Selection.NumberFormat = "0.00"
    Application.ScreenUpdating = True
    MsgBox ("Done!")

    End Sub

    Sub Getprice(Mystr, darget)
    Sheets("Macroveld").Select
    ConnectString = "URL;http://finance.yahoo.com/q?s=" & Mystr
    With ActiveSheet.QueryTables.Add(Connection:= _
    ConnectString, Destination:=Range("$A$3"))
    .FieldNames = True
    .RowNumbers = False
    .FillAdjacentFormulas = False
    .PreserveFormatting = True
    .RefreshOnFileOpen = False
    .BackgroundQuery = True
    .RefreshStyle = xlInsertDeleteCells
    .SavePassword = False
    .SaveData = True
    .AdjustColumnWidth = True
    .RefreshPeriod = 0
    .WebSelectionType = xlSpecifiedTables
    .WebFormatting = xlWebFormattingNone
    .WebTables = "14"
    .WebPreFormattedTextToColumns = True
    .WebConsecutiveDelimitersAsOne = True
    .WebSingleBlockTextImport = False
    .WebDisableDateRecognition = False
    .WebDisableRedirections = False
    .Refresh BackgroundQuery:=False
    End With
    Range("B3").Select
    Selection.Copy
    Sheets("Blad1").Select
    darget.Select
    ActiveSheet.Paste

    Sheets("Macroveld").Select
    Range("A1:e14").Select
    Application.CutCopyMode = False
    Selection.QueryTable.Delete
    Selection.ClearContents
    End Sub
    Last edited by Tano; 07-25-2007 at 10:18 AM.

  4. #4
    Forum Contributor SOS's Avatar
    Join Date
    01-26-2004
    Location
    Glasgow, Scotland
    MS-Off Ver
    Excel 2003
    Posts
    327
    Sorry, Tano, don't know the answer to that one. I did do a google search on refresh backgroundquery and got some results. You might want to try that.

    Regards

    Seamus

  5. #5
    Registered User
    Join Date
    07-25-2007
    Posts
    3
    Yeah, that's how I found the option explicit thing.

    Thanks for the help anyway!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1