I have this code and i want to make A and B as 2 different ranges, but it doesnt seem to work.. Its giving me error 1004 when i try to run Set A.
Private Sub CommandButton1_Click5()
Dim snome As String
Dim myP As Integer
Dim Data As Date
Dim data_init As Date
Dim Data_InitVer As Date
Dim Linha_q As Integer
Dim irow As Integer
Dim Correlation As Double
Dim Res As Variant
Dim A As Range
Dim B As Range
mypFundo = Worksheets("Cotas").Cells.Find("11.392.165/0001-72").Column
mypSMLL = Worksheets("Cotas").Cells.Find("SMLL").Column
mypIBOV = Worksheets("Cotas").Cells.Find("Ibovespa").Column
ULTIMA_LINHA = Worksheets("Cotas").Cells(Rows.Count, mypFundo).End(xlUp).Row
Data = Worksheets("Cotas").Cells(ULTIMA_LINHA, 1)
'meio que tu tem usando o irow ja calculado
ano = Year(Data)
data_init = DateSerial(ano, 1, 1)
'é o primeiro dia útil?
Data_InitVer = Application.WorksheetFunction.WorkDay(data_init, 1, Worksheets("Feriados").Range("A1:A1000"))
snome = ActiveWorkbook.Name
Res = Application.Match(CDbl(Data_InitVer), Workbooks(snome).Worksheets("Cotas").Columns(1), 0)
If Not IsError(Res) Then
Linha_q = Res
End If
irow = Worksheets("Cotas").Cells(Rows.Count, mypFundo).End(xlUp).Row
Set A = Range(Worksheets("Cotas").Cells(Linha_q, mypFundo), Worksheets("Cotas").Cells(ULTIMA_LINHA, mypFundo))
Set B = Range(Worksheets("Cotas").Cells(Linha_q, mypIBOV), Worksheets("Cotas").Cells(ULTIMA_LINHA, mypIBOV))
Correlation = Application.WorksheetFunction.Correl(A, B)
End Sub
Bookmarks