Sub GetFinvizData()
Dim RowCt As Integer
Dim RowTot As Variant, RowTotSub As Variant
Dim Z As Integer, Y As Integer, x As Integer
Dim strFinSite As String
Dim strFin(1 To 8) As String
strFin(1) = "basicmaterials"
strFin(2) = "consumergoods"
strFin(3) = "financial"
strFin(4) = "healthcare"
strFin(5) = "industrialgoods"
strFin(6) = "services"
strFin(7) = "technology"
strFin(8) = "utilities"
For Y = 1 To 8
Sheets(strFin(Y)).Activate
Range("A2", "K2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.ClearContents
Selection.ClearFormats
Next Y
For Z = 1 To 8
Sheets("Raw").Activate
Range("A1").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.ClearContents
'Download Stock Data
strFinSite = "http://finviz.com/export.ashx?v=151&f=ind_stocksonly,sec_" & strFin(Z) & ",sh_avgvol_o500,sh_opt_optionshort,sh_price_o10&ft=4&o=industry&c=1,2,4,42,43,44,45,46,47,65,68"
QueryQuote:
With Sheets("Raw").QueryTables.Add(Connection:="URL;" & strFinSite, Destination:=Sheets("Raw").Range("a1"))
.BackgroundQuery = True
.TablesOnlyFromHTML = False
.Refresh BackgroundQuery:=False
.SaveData = True
End With
Sheets("Raw").Range("a1").CurrentRegion.TextToColumns Destination:=Sheets("Raw").Range("a1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, _
Semicolon:=False, Comma:=True, Space:=False, other:=True, OtherChar:=",", FieldInfo:=Array(1, 2)
Sheets("Raw").Columns("A:B").ColumnWidth = 12
Range("A1").Select
'Filters bullish reversing trades based on:
'-Week and month performance positive
'-Half performance negative
Sheets("Raw").Activate
RowTot = ActiveSheet.UsedRange.Rows.Count
For RowCt = 2 To RowTot
If (Sheets("Raw").Cells(RowCt, 7).Value < 0 And Sheets("Raw").Cells(RowCt, 5).Value > 0 And _
Sheets("Raw").Cells(RowCt, 4).Value > 0) Then
Range("A" & RowCt & ":" & "K" & RowCt).Select
Selection.Copy Destination:=Sheets(strFin(Z)).Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
End If
Next RowCt
Sheets(strFin(Z)).Activate
RowTotSub = ActiveSheet.UsedRange.Rows.Count
x = 1
Do Until x > RowTot
If Cells(x, 1).Interior.TintAndShade = 0 And Cells(x + 1, 1).Value = 0 Then
Cells(x, 1).Select
Range(Selection, Cells(x, 11)).Select
Exit Do
ElseIf Cells(x, 1).Interior.TintAndShade = 0 And Cells(x, 1).Value <> 0 Then
Cells(x, 1).Select
Range(Selection, Cells(x, 11)).Select
Range(Selection, Selection.End(xlDown)).Select
Exit Do
End If
x = x + 1
Loop
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorAccent6
.TintAndShade = 0.799981688894314
.PatternTintAndShade = 0
End With
'Filters bullish continuation trades based on:
'-Month, quarter, & half performance positive
'-Week performance negative
Sheets("Raw").Activate
RowTot = ActiveSheet.UsedRange.Rows.Count
For RowCt = 2 To RowTot
If (Sheets("Raw").Cells(RowCt, 4).Value < 0 And Sheets("Raw").Cells(RowCt, 5).Value > 0 And _
Sheets("Raw").Cells(RowCt, 6).Value > 0 And Sheets("Raw").Cells(RowCt, 7).Value > 0) Then
Range("A" & RowCt & ":" & "K" & RowCt).Select
Selection.Copy Destination:=Sheets(strFin(Z)).Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
End If
Next RowCt
Sheets(strFin(Z)).Activate
RowTotSub = ActiveSheet.UsedRange.Rows.Count
x = 1
Do Until x > RowTot
If Cells(x, 1).Interior.TintAndShade = 0 And Cells(x + 1, 1).Value = 0 Then
Cells(x, 1).Select
Range(Selection, Cells(x, 11)).Select
Exit Do
ElseIf Cells(x, 1).Interior.TintAndShade = 0 And Cells(x, 1).Value <> 0 Then
Cells(x, 1).Select
Range(Selection, Cells(x, 11)).Select
Range(Selection, Selection.End(xlDown)).Select
Exit Do
End If
x = x + 1
Loop
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorAccent1
.TintAndShade = 0.799981688894314
.PatternTintAndShade = 0
End With
Application.Wait (Now + TimeValue("0:00:05"))
Next Z
End Sub
Bookmarks