Hi guys I need help with a VBA program I am trying to write. This is my first ever program so go easy haha.
Basically I am trying to calculate a correlation table using VBA rather than by hand. I have a table of values that starts (the corner is in) cell T3. The values go to the right and down.
Two values are taken from the table into cells N1 and N2 which drags values from a long list into an array. The correl of the two arrays are calculated in Q3.
I then want the formula to take the value that is calculated in Q3 and put it into the corresponding area on the correl table. But the correl calculation (formula in cell Q3) isn't updating between each iteration. I am using Sheets("Sheet4").calculate for it but it doesn't seem to be working. I have also tried .calculate with range commands and activecell and activesheet and none seem to work. The full code rn is as follows;
Sub proFirst()
Sheets("Sheet4").Select
Dim count1 As Integer
Dim count2 As Integer
Dim cor1 As String
Dim cor2 As String
Dim cor1offset As Integer
Dim cor2offset As Integer
Dim correl As Single
count1 = 0
count2 = 0
com1 = "hello"
com2 = "hello"
cor1offset = 1
cor2offset = 1
correl = 0.01
Do While count1 < 3
Do While count2 < 3
Range("T3").Offset(cor1offset, 0).Select
com1 = ActiveCell.value
Range("N1").value = cor1
Range("T3").Offset(0, cor2offset).Select
com2 = ActiveCell.value
Range("N2").value = cor2
Sheets("Sheet4").Calculate
Range("Q3").Select
correl = ActiveCell.value
Range("T3").Offset(cor1offset, cor2offset).value = correl
count2 = count2 + 1
cor2offset = cor2offset + 1
Loop
count2 = 0
cor2offset = 1
cor1offset = cor1offset + 1
count1 = count1 + 1
Loop
End Sub
What am I doing wrong?
Basically I am trying to calculate a correlation table using VBA rather than by hand. I have a table of values that starts (the corner is in) cell T3. The values go to the right and down.
Two values are taken from the table into cells N1 and N2 which drags values from a long list into an array. The correl of the two arrays are calculated in Q3.
I then want the formula to take the value that is calculated in Q3 and put it into the corresponding area on the correl table. But the correl calculation (formula in cell Q3) isn't updating between each iteration. I am using Sheets("Sheet4").calculate for it but it doesn't seem to be working. I have also tried .calculate with range commands and activecell and activesheet and none seem to work. The full code rn is as follows;
Sub proFirst()
Sheets("Sheet4").Select
Dim count1 As Integer
Dim count2 As Integer
Dim cor1 As String
Dim cor2 As String
Dim cor1offset As Integer
Dim cor2offset As Integer
Dim correl As Single
count1 = 0
count2 = 0
com1 = "hello"
com2 = "hello"
cor1offset = 1
cor2offset = 1
correl = 0.01
Do While count1 < 3
Do While count2 < 3
Range("T3").Offset(cor1offset, 0).Select
com1 = ActiveCell.value
Range("N1").value = cor1
Range("T3").Offset(0, cor2offset).Select
com2 = ActiveCell.value
Range("N2").value = cor2
Sheets("Sheet4").Calculate
Range("Q3").Select
correl = ActiveCell.value
Range("T3").Offset(cor1offset, cor2offset).value = correl
count2 = count2 + 1
cor2offset = cor2offset + 1
Loop
count2 = 0
cor2offset = 1
cor1offset = cor1offset + 1
count1 = count1 + 1
Loop
End Sub
What am I doing wrong?