473,326 Members | 2,805 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Excel-Macros-Loops

Here is the issue.

In a workbook I have 100 sheet with data at column b2:b1700 in everyone of them. I want to calculate the correlation btw all possible pairs. For sheet2 and sheet3 the function is =CORREL(sheet2!R2C2:R1700C2,sheet3!R2C2:R1700C2)

I have tried to create a macro

For i = 2 To Sheets.Count
x = Sheets(i).Name
Sheets(1).Cells(1, i).FormulaR1C1 = "=CORREL(x!R2C2:R1700C2,sheet3!R2C2:R1700C2)"
Next i

When I run the macro it wants me to specify a file x to read from instead of going to the currect sheet.
Eliminating the second line and replacind x with i in the correlation same thing happens.
I have tried a lot of things...

Does anybody know how to do it?
Nov 8 '06 #1
7 2991
willakawill
1,646 1GB
Here is the issue.

In a workbook I have 100 sheet with data at column b2:b1700 in everyone of them. I want to calculate the correlation btw all possible pairs. For sheet2 and sheet3 the function is =CORREL(sheet2!R2C2:R1700C2,sheet3!R2C2:R1700C2)

I have tried to create a macro

For i = 2 To Sheets.Count
x = Sheets(i).Name
Sheets(1).Cells(1, i).FormulaR1C1 = "=CORREL(x!R2C2:R1700C2,sheet3!R2C2:R1700C2)"
Next i

When I run the macro it wants me to specify a file x to read from instead of going to the currect sheet.
Eliminating the second line and replacind x with i in the correlation same thing happens.
I have tried a lot of things...

Does anybody know how to do it?
Hi. Interesting problem. I see that you have included the variable x in the formula string. Excel will not know the value of x when it looks at the formula.
This might work better:
Expand|Select|Wrap|Line Numbers
  1. stFormula = "=CORREL(" _
  2.              & Sheets(i).Name _
  3.              & "!R2C2:R1700C2,sheet3!R2C2:R1700C2)"
  4.  
  5. Sheets(1).Cells(1, i).FormulaR1C1 = stFormula
  6.  
Good luck
Nov 8 '06 #2
Killer42
8,435 Expert 8TB
Hi. Interesting problem. I see that you have included the variable x in the formula string. Excel will not know the value of x when it looks at the formula.
...
Actually, I think the only problem with the original code is that the x was inside the quotes, and thus inserted directly as part of the string, rather than its value being used. Anyway...

Do you think this would work?
Expand|Select|Wrap|Line Numbers
  1. For I = 1 To Sheets.Count - 1
  2.   For J = I + 1 To Sheets.Count
  3.     Sheets(1).Cells(1, I).FormulaR1C1 = "=CORREL(" & _
  4.       Sheets(I).Name & "!R2C2:R1700C2, " & _
  5.       Sheets(J).Name & "!R2C2:R1700C2)"
  6.   Next I
  7. Next
The idea of this is to use a nested FOR loop to go through all the possible combinations - 9,801 of them, I think. Or was the intention only to check each sheet against the next one, or what?
Nov 9 '06 #3
Killer42
8,435 Expert 8TB
...Or was the intention only to check each sheet against the next one, or what?
Yeah, on second thought my code would be simply overwriting the same values 99 times. So I guess the intention must have been just to check each sheet against the next. Or possibly each of the 50 pairs of sheets.
Nov 9 '06 #4
willakawill
1,646 1GB
Yeah, on second thought my code would be simply overwriting the same values 99 times. So I guess the intention must have been just to check each sheet against the next. Or possibly each of the 50 pairs of sheets.
Hey Killer.
Are you getting a little punch drunk with these questions? ;)

Now you are answering questions that have already been answered. Get some sleep :)
Nov 9 '06 #5
Killer42
8,435 Expert 8TB
Hey Killer.
Are you getting a little punch drunk with these questions? ;)

Now you are answering questions that have already been answered. Get some sleep :)
Not only that, but I'm criticising my own posts. :)

Actually, while I could do with more sleep, it's lunch time here. But I'm doing about 28 things at once, plus jumping in and out of these forums, etc.

I'm going to have to cut back on something, and theScripts doesn't pay the bills.
Nov 9 '06 #6
Thank you very very much

With some loops I made it work nicely but it takes a little time to calculate all the pairs.

Thanks again
Nov 9 '06 #7
Killer42
8,435 Expert 8TB
Thank you very very much
With some loops I made it work nicely but it takes a little time to calculate all the pairs.
I suppose you can only expect so much. I'm not familiar with the CORREL function, but to process 99 (or 50, or whatever) lots of 1700 cells has to take some time.

By the way, just out of curiosity, could you show us the code you ended up with?
Nov 9 '06 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

13
by: Allison Bailey | last post by:
Hi Folks, I'm a brand new Python programmer, so please point me in the right direction if this is not the best forum for this question.... I would like to open an existing MS Excel spreadsheet...
3
by: Otie | last post by:
I found the following under the GetObject help notes and in the example for GetObject: "This example uses the GetObject function to get a reference to a specific Microsoft Excel worksheet...
6
by: Matthew Wieder | last post by:
I have the following requirements: Build a stand-alone C# application that asks the user to click in a cell in an Excel spreadsheet, and then displays the address of that cell in the C#...
14
by: pmud | last post by:
Hi, I need to use an Excel Sheet in ASP.NET application so that the users can enter (copy, paste ) large number of rows in this Excel Sheet. Also, Whatever the USER ENETRS needs to go to the...
22
by: Howard Kaikow | last post by:
There's a significant problem in automating Excel from VB .NET. Reminds me of a problem I encountered almost 3 years ago that was caused by the Norton Auntie Virus Office plug-in. Can anybody...
9
by: Anthony | last post by:
To me, creating Excel 2003 spreadsheets programmatically via VB.NET hasn't really changed since the days of VB6. That is, I'd do something similar to this Code: Dim ExcelApp As...
7
by: Alain \Mbuna\ | last post by:
Hi everybody. In my program I have some data that is calculated after some input from the user. I have written some code that opens an Excel workbook, with 5 worksheets and the calculated data...
16
by: alexia.bee | last post by:
Hi all, In some weird reason, excel instance won;t die if i remove the comment from 4 lines of setting values into struct. here is a snipcode public...
9
by: Doug Glancy | last post by:
I got the following code from Francesco Balena's site, for disposing of Com objects: Sub SetNothing(Of T)(ByRef obj As T) ' Dispose of the object if possible If obj IsNot Nothing AndAlso...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.