VBA wont calculate cells during loop

ExcelHank

New Member
Joined
Dec 8, 2017
Messages
4
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?
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Welcome to the Board! Maybe...
Code:
Application.Calculate
]
HTH. Dave
ps. please use code tags
 
Last edited:
Upvote 0
I have tried that as well, still no dice.

Strangely, after the program is finished running cells N1 and N2 are still blank so maybe there is an issue with actually placing the values in those cells?
 
Upvote 0
As far as I can see, Cor1 and Cor2 have no values ergo N1 & N2 have no values. Com1 & Com2 have values that don't do anything. Spelling? Dave
 
Upvote 0
Found the fix! The cor/com error was actually while trying to debug. The main error was that I noobishly set value as a variable and so VBA refused to recognize it as a command (which is why it was uncapitalized). I cleared the code table and coppied into new file and now it works perfectly! Thank you for the help!!
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,279
Members
452,630
Latest member
OdubiYouth

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top