473,386 Members | 1,720 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,386 software developers and data experts.

Using a variable to select multiple sheets in Excel

Hi there,

I need help with Visual Basic.
I am trying to use a variable to select different sheets

Example :

I would like to have this formula in Cells A1 of my summary sheet

Range("A1").Select
ActiveCell.FormulaR1C1 = "=IF(Sheet1!R[5]C[1]=3,""Good"",""Bad"")"

Similarly, in Cell A2 for my summary sheet, I would like to have the same formula as above, however I would like to refer to Sheet2 instead of Sheet1

Range("A2").Select
ActiveCell.FormulaR1C1 = "=IF(Sheet2!R[5]C[1]=3,""Good"",""Bad"")"

How do I make the sheets that I refer to a variable, so that I can use a loop to fill in Cells A1 to Cells A300 of my summary sheet, with the same formula but refering to 300 different sheets, ie Sheet1 to Sheet300?

Can anyone help me?

Thanks
Sep 10 '06 #1
1 9328
Hi there,

I need help with Visual Basic.
I am trying to use a variable to select different sheets

Example :

I would like to have this formula in Cells A1 of my summary sheet

Range("A1").Select
ActiveCell.FormulaR1C1 = "=IF(Sheet1!R[5]C[1]=3,""Good"",""Bad"")"

Similarly, in Cell A2 for my summary sheet, I would like to have the same formula as above, however I would like to refer to Sheet2 instead of Sheet1

Range("A2").Select
ActiveCell.FormulaR1C1 = "=IF(Sheet2!R[5]C[1]=3,""Good"",""Bad"")"

How do I make the sheets that I refer to a variable, so that I can use a loop to fill in Cells A1 to Cells A300 of my summary sheet, with the same formula but refering to 300 different sheets, ie Sheet1 to Sheet300?

Can anyone help me?

Thanks


Not sure exactly what you want, but this might help point you in the right direction.

Ken


For i = 1 To 3

' use the line below to write to different sheets
' Sheets(i).Range("A" & i).Select

' will write all formulas on sheet 1
Range("A" & i).Select
FormulaToWrite = "=IF(Sheet" & i & "!R[5]C[1]=3,""Good"",""Bad"")"
ActiveCell.FormulaR1C1 = FormulaToWrite

Next i
Sep 11 '06 #2

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

Similar topics

9
by: Scott Beavers | last post by:
I'm trying to create a form in Excel to sort from the form and take the data to another worksheet. I am very new to this and any help would be appreciated. I have a value in a cell that will...
1
by: barma16 | last post by:
I've hit a bit of a brick wall here, and could use some advice. I have an Access application whose output is a four-tab Excel spreadsheet where three of the four tabs are the result of database...
3
by: Scott | last post by:
I want to search 5 or 6 very big excel spreadsheets looking for specific data held in them. The search would be using clients surnames and maybe postcodes to eventually find the correct person. ...
1
by: garry.oxnard | last post by:
Can anyone help me to solve a problem which involves switching from Access to Excel (then back to Access) programatically please? I have an Excel template which, on open, also opens an Access...
0
by: SirMikesALot | last post by:
I'm pretty good at Excel, but my skills in Visual Basic are very limited. I found script on-line that creates & opens a user form, allows you to select your worksheets, prints the selected...
0
by: Steve1974 | last post by:
Hi All I am currently using Access to output to excel. The creation of the worksheet goes ok, and then I have a piece of code (recorded from an Excel macro) to create pick lists for two columns...
5
by: njb35 | last post by:
Hi all I'm beginning my foray from VBA into VB 2005 Express, and enjoying some of the efficiencies it provides! I'm stuck with some dataset handling however that I _think_ can be automated but...
2
ltworf13
by: ltworf13 | last post by:
The file run through and grabs my csf files but then stops when it get's to my left file. For some reason the Tempcell object variable get's lost and becomes nothing. When I step through the code I...
2
by: Whasigga | last post by:
Hello I am working on a project to export data from a query into an Excel file. I have a form with a button on it and the button when clicked runs a function that is supposed to run the query and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.