[FONT=Fixedsys]Option Explicit[/FONT]
[FONT=Fixedsys][/FONT]
[FONT=Fixedsys]Const sURL As String = "[/FONT][URL="http://investor.shareholder.com/ctrp/new/stockquote.cfm"][FONT=Fixedsys]http://investor.shareholder.com/ctrp/new/stockquote.cfm[/FONT][/URL][FONT=Fixedsys]"
Const sSheet As String = "[COLOR=red][B]Sheet1[/B][/COLOR]"[/FONT]
[FONT=Fixedsys][/FONT]
[FONT=Fixedsys]Dim ws As Worksheet
Dim iLastRow As Long
Dim iColumn As Integer[/FONT]
[FONT=Fixedsys][/FONT]
[FONT=Fixedsys]Public Sub GetStockInfo()[/FONT]
[FONT=Fixedsys][/FONT]
[FONT=Fixedsys] Dim oCell As Range
Set ws = ThisWorkbook.Sheets(sSheet)
iLastRow = ws.Cells(ws.Rows.Count, 1).End(xlUp).Row
Application.ScreenUpdating = False
If iLastRow = 1 Then
ws.Range("A1:P1").Font.Bold = True
ws.Range("A1:P1").Value = Array( _
"Date", "Last", "Change", "% Change", "Open", "Bid", "Ask", "High", "Low", "Prev. Close", _
"Year High", "Year Low", "Volume", "EPS", "Mkt Cap", "Last Q'ly Div/Share")
Columns("A:P").Select
ws.Range("A1:P1").HorizontalAlignment = xlCenter
End If[/FONT]
[FONT=Fixedsys][/FONT]
[FONT=Fixedsys] Call GetWebPage
For Each oCell In Range("A" & CStr(iLastRow + 4) & ":C" & CStr(iLastRow + 13))
oCell = Replace(oCell.Text, "$", "")
oCell = Replace(oCell.Text, "*", "")
oCell = Replace(oCell.Text, "/ Share", "")
Next oCell
ws.Cells(iLastRow + 1, 1) = Format(Now(), "dd/mm/yyyy")
Call MoveData
Call FormatRange
ws.Columns("A:P").EntireColumn.AutoFit
For iColumn = 1 To 16
ws.Columns(iColumn).ColumnWidth = ws.Columns(iColumn).ColumnWidth * 1.1
Next iColumn
Application.ScreenUpdating = False
End Sub[/FONT]
[FONT=Fixedsys][/FONT]
[FONT=Fixedsys]Sub FormatRange()
ws.Range("A" & CStr(iLastRow + 1)).NumberFormat = "dd/mm/yyyy;@"
ws.Range("B" & CStr(iLastRow + 1) & ":C" & CStr(iLastRow + 1) & "," _
& "E" & CStr(iLastRow + 1) & ":L" & CStr(iLastRow + 1) & "," _
& "N" & CStr(iLastRow + 1) & "," _
& "P" & CStr(iLastRow + 1)).NumberFormat = "[$$-1009]#,##0.00"
ws.Range("D" & CStr(iLastRow + 1)).NumberFormat = "0.00%"
ws.Range("M" & CStr(iLastRow + 1) & ",O" & CStr(iLastRow + 1)).NumberFormat = "#,##0"
ws.Range("A" & CStr(iLastRow + 1) & ":P" & CStr(iLastRow + 1)).HorizontalAlignment = xlCenter[/FONT]
[FONT=Fixedsys]End Sub[/FONT]
[FONT=Fixedsys][/FONT]
[FONT=Fixedsys]Sub GetWebPage()
With ActiveSheet.QueryTables.Add(Connection:="URL;" & sURL, Destination:=Sheets(sSheet).Range("A" & CStr(iLastRow + 2)))
.Name = "stockquote_1"
.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 = "3"
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
End Sub[/FONT]
[FONT=Fixedsys][/FONT]
[FONT=Fixedsys]Sub MoveData()[/FONT]
[FONT=Fixedsys][/FONT]
[FONT=Fixedsys] Range("A" & CStr(iLastRow + 5) & ":C" & CStr(iLastRow + 5)).Copy Destination:=Range("B" & CStr(iLastRow + 1) & ":D" & CStr(iLastRow + 1))
Range("A" & CStr(iLastRow + 7) & ":C" & CStr(iLastRow + 7)).Copy Destination:=Range("E" & CStr(iLastRow + 1) & ":G" & CStr(iLastRow + 1))
Range("A" & CStr(iLastRow + 9) & ":C" & CStr(iLastRow + 9)).Copy Destination:=Range("H" & CStr(iLastRow + 1) & ":J" & CStr(iLastRow + 1))
Range("A" & CStr(iLastRow + 11) & ":C" & CStr(iLastRow + 11)).Copy Destination:=Range("K" & CStr(iLastRow + 1) & ":M" & CStr(iLastRow + 1))
Range("A" & CStr(iLastRow + 13) & ":C" & CStr(iLastRow + 13)).Copy Destination:=Range("N" & CStr(iLastRow + 1) & ":P" & CStr(iLastRow + 1))
Range("A" & CStr(iLastRow + 2) & ":C" & CStr(iLastRow + 13)).ClearContents
End Sub[/FONT]