Guest User

dung help

a guest
Apr 15th, 2011
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Sub GetLevels()
  2.     Application.Calculation = xlManual
  3.     cleanup
  4.     Dim ws As Worksheet
  5.     Set ws = ActiveSheet
  6.     Dim c As Range
  7.     Dim r As Range
  8.     If IsEmpty(Range("D1")) Then
  9.         Set r = Cells(1, 3)
  10.     Else
  11.         Set r = Range(Cells(1, 3), Range("C1").End(xlToRight))
  12.     End If
  13.    
  14.     For Each c In r.Cells
  15.         If Not IsEmpty(c) Then
  16.             GetPlayerLevels c.Value, c.Offset(1, 0)
  17.             With Range(c.Offset(1, 0), c.Offset(25, 0))
  18.                 .ColumnWidth = 5
  19.                 .Interior.ColorIndex = xlNone
  20.                 .FormatConditions.Delete
  21.                 .FormatConditions.Add Type:=xlCellValue, Operator:=xlGreaterEqual _
  22.                     , Formula1:="=$A$2"
  23.                 .FormatConditions(1).Font.ColorIndex = xlAutomatic
  24.                 .FormatConditions(1).Interior.ColorIndex = 4
  25.                 .FormatConditions.Add Type:=xlCellValue, Operator:=xlGreaterEqual _
  26.                     , Formula1:="=($A$2-4) / ( 1 + 0.04)"
  27.                 With .FormatConditions(2).Interior
  28.                     .ColorIndex = 35
  29.                     .PatternColorIndex = 4
  30.                     .Pattern = xlGray50
  31.                 End With
  32.                 .FormatConditions.Add Type:=xlCellValue, Operator:=xlGreaterEqual _
  33.                     , Formula1:="=($A$2-6) / ( 1 + 0.06)"
  34.                 With .FormatConditions(3).Interior
  35.                     .ColorIndex = 35
  36.                 End With
  37.                
  38.                 'borders
  39.                .Borders(xlDiagonalDown).LineStyle = xlNone
  40.                 .Borders(xlDiagonalUp).LineStyle = xlNone
  41.                 With .Borders(xlEdgeLeft)
  42.                     .LineStyle = xlContinuous
  43.                     .Weight = xlThin
  44.                     .ColorIndex = 15
  45.                 End With
  46.                 With .Borders(xlEdgeTop)
  47.                     .LineStyle = xlContinuous
  48.                     .Weight = xlThin
  49.                     .ColorIndex = 15
  50.                 End With
  51.                 With .Borders(xlEdgeBottom)
  52.                     .LineStyle = xlContinuous
  53.                     .Weight = xlThin
  54.                     .ColorIndex = 15
  55.                 End With
  56.                 With .Borders(xlEdgeRight)
  57.                     .LineStyle = xlContinuous
  58.                     .Weight = xlThin
  59.                     .ColorIndex = 15
  60.                 End With
  61.                 With .Borders(xlInsideHorizontal)
  62.                     .LineStyle = xlContinuous
  63.                     .Weight = xlThin
  64.                     .ColorIndex = 15
  65.                 End With
  66.             End With
  67.         End If
  68.     Next
  69.     Dim r2 As Range
  70.     Set r2 = Range(Cells(2, 3), Cells(26, 2 + r.Columns.Count))
  71.    
  72.     Dim m As Range
  73.     Dim MaxVal As Integer
  74.     Dim c2 As Range
  75.     For Each c In r2.Rows
  76.         MaxVal = Application.WorksheetFunction.Max(c)
  77.         For Each c2 In c.Cells
  78.             If c2.Value = MaxVal Then
  79.                 With c2
  80.                     .Font.Bold = True
  81.                     With .Interior
  82.                         .ColorIndex = 34
  83.                         .Pattern = xlSolid
  84.                     End With
  85.                 End With
  86.             End If
  87.            
  88.         Next
  89.        
  90.  
  91.     Next
  92.    
  93.     Application.Calculation = xlAutomatic
  94.  
  95. End Sub
  96.  
  97.  
  98. Sub GetPlayerLevels(user As String, outputstart As Range)
  99.  
  100.  
  101.     Dim activews As Worksheet
  102.     Dim ws As Worksheet
  103.     Set activews = ActiveSheet
  104.     Set ws = Sheets.Add
  105.     activews.Activate
  106.    
  107.     On Error Resume Next
  108.     Err.Clear
  109.    
  110.     Dim urlstr As String
  111.     urlstr = "URL;http://hiscore.runescape.com/index_lite.ws?player=" & user
  112.     ws.Columns("A:A").NumberFormat = "@"
  113.    
  114.     With ws.QueryTables.Add(Connection:= _
  115.        urlstr, _
  116.           Destination:=ws.Range("a1"))
  117.        .BackgroundQuery = True
  118.        .TablesOnlyFromHTML = True
  119.        .Refresh BackgroundQuery:=False
  120.        .SaveData = True
  121.     End With
  122.     With ws.Columns("A:A")
  123.         .TextToColumns Destination:=Range("B1"), DataType:=xlDelimited, _
  124.         TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
  125.         Semicolon:=False, Comma:=True, Space:=False, Other:=False, FieldInfo _
  126.         :=Array(Array(1, 1), Array(2, 1), Array(3, 1)), TrailingMinusNumbers:=True
  127.     End With
  128.        
  129.    
  130.     If Err.Number = 0 Then
  131.         Range(outputstart, outputstart.Offset(24, 0)).Value = ws.Range("C2:C26").Value
  132.     ElseIf Err.Number = 1004 Then
  133.         Range(outputstart, outputstart.Offset(24, 0)).Value = -1
  134.     End If
  135.    
  136.    
  137.     Application.DisplayAlerts = False
  138.     ws.Delete
  139.     Application.DisplayAlerts = True
  140.    
  141.    
  142.    
  143. End Sub
  144.  
  145. Sub cleanup()
  146.     With Range("C2:G26")
  147.         .Clear
  148.     End With
  149.     Application.Calculation = xlAutomatic
  150. End Sub
Advertisement
Add Comment
Please, Sign In to add comment