Referencing Sheet Code Names By Variable
I have a set of worksheets (Sheet31 through Sheet49 by codename) produced by a machine in the lab. I want to create a summary sheet that references cells in those worksheets.
Rather than go through the annoyance of doing this manually 40+ times I'm working on creating a macro to populate the summary sheet for me.
This is what I have so far
For J = 31 To 49
ResultSht = SheetJ.Name
Sheet1.Activate
ActiveSheet.Range("A4").End(xlDown).Offset(1, 0).Select
It hangs up on the "SheetJ.Name" however. My objective is to be using the object SheetJ, where the object SheetJ is the codename of the results sheet I'm trying to reference (for example, in the first pass through the loop it would be Sheet31). Could someone point out my mistake in this object reference?
View Complete Thread with Replies
Sponsored Links:
Related Forum Messages:
Variable Sheet Names In VBA
Running Windows CP; Excel 2003 The Board looks full of some interesting issues today. I'm working on a workbook that hides and unhides a lot of columns depending on the month the user has selected. No problems here. The sheets are named regionally, ie National 2008, California 2008 etc. The user is able to select the month and the year from separate combo boxes. So when 2009 comes around I will need to rewrite many lines of code to point the VBA to the new worksheet names like National 2009, California 2009. My question is, is there a way to reference either variable worksheet names in the VBA or some other manner in which to write the code so I don't need to rewrite every year change? I currently reference the sheets something like Sheets ("National 2008").Range("H:H").EntireColumn.Hidden=True
View Replies!
View Related
Reference Sheets With Variable Sheet Names
I have a workbook with multiple sheets. There is an overview sheet and then 14 sheets allowing for 14 days worth of schedule information. There are then 3 sheets following the 14 days to total some information. The workbook users frequently change the sheet names of the 14 sheets to reflect days of the week. I'm creating a copy for distribution that takes the active workbook and copies the values to a new workbook. There are columns that I would like to delete from the 14 day sheets and that would be easy enough if the sheet names were never changed. The code I'm using currently follows (my thanks to Turtle 44 for helping on that section) Sub Copy_Visible_Sheets() Dim arr() As String Dim i As Integer Dim WB As Workbook Dim WS As Worksheet Set WB = ActiveWorkbook Application. ScreenUpdating = False 'Make sure template is saved as .xls If Not ThisWorkbook.Saved Then MsgBox "Please save this workbook before generating a Client Copy." Else
View Replies!
View Related
Hyperlink Code For Sheet Names With Spaces Or Dashes
I believe I have 99% of what I need. The code below has one bug. (See just the underlined text for a very quick overview. The rest is detail.) My goal is to generate a TOC that: 1) has the VBA run from my Personal Workbook. 2) can be run in any worksheet of any open workbook. 3) can be run in a worksheet of any name. 4) will insert itself at the currently active cell. 5) has entries hyperlinking to the referenced worksheets - of any name. Right now, I'm stuck with the last point. The macro below will generate the TOC at the currently active cell. The TOC will be hyperlinks to the referenced worksheets. However, if the referenced worksheet contains a space, dash, or other special character then the generated hyperlink is broken. For example, if the referenced worksheet is "sheet1" then the hyperlink generated works just fine. However, if the referenced worksheet is "sheet-1" then the generated hyperlink doesn't work. Sub IndexList() Dim objSheet As Object Dim intRow As Integer Dim strCol As Integer Set objSheet = Excel.Sheets intRow = ActiveCell.Row 'Start writing in active row strCol = ActiveCell.Column 'Start writing in active column For Each objSheet In ActiveWorkbook.Sheets Cells(intRow, strCol).Select ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="", SubAddress:= _ objSheet.Name & "!A1", TextToDisplay:=objSheet.Name intRow = intRow + 1 Next End Sub
View Replies!
View Related
VBA Code For Listing The Sheet Names Of Deleted Sheets
I have a workbook with 20+ sheets in it, I add sheets and delete sheets on a daily basis, except for one sheet that is like my summary sheet. Is there a code, formula, or magic spell that will list the names of the sheets that I have deleted? For instance, if my workbook has 50 sheets and I delete 49 of them, I want to see cells A1 thru A49 (or where ever I wish to place them) filled with the names of the sheets I just deleted.
View Replies!
View Related
Cross Referencing Names On Different Worksheets
I have three different sheets, each with a column of names, titled "list1, list2, list3." I also have a fourth list of names on a sheet titled "masterlist." I am wondering if there is any way I could cross check the three lists against the master list to see if any names appear on the master list but do not appear on any of the three lists. Is there any way I can cross reference the master list with each of these lists?
View Replies!
View Related
Add Formula Via Macro Code With Variable As Sheet Name
I have a front sheet with a list of all the sheets in the workbook in column A. In column B I need to use the counta function to count the number of entries in the corresponding sheet to column A. As there are 70 sheets I'd thought I'd use a Macro but I'm having great difficulties. I've done a search but can't find what I'm looking for. So heres part of my code (it uses loops etc which I've managed but this just errors) cell.Offset(0, 1).FormulaR1C1 = "=counta(" & str2&" C[-1])-1" The str2 is the string name to reference the sheet in the formula (for example sheet1), I can't figure out how to enter this into the code so it works and is accepted.
View Replies!
View Related
Variable Data Referencing
I have a word table(s) which I need to paste into excel, its a quotation sheet and this document always has the same basic format. I then need to copy across specification items to another sheet between 2 points in column A ie between points TEXT1 (A25) and TEXT2(A40) so cells A26:A39 in this instance but this can be between 1 or 100 items. Text 2 is the start of a costing section and wouldn't be transferred. What i am looking to do is write a formula which will look in sheet1 at column A and find "TEXT 1" at A25 then copy items across until it comes to "TEXT2" at A40 but is flexible enough to cope with various numbers of items.
View Replies!
View Related
Referencing A Value In Variable Length Columns.
I have a SS I would like to reference a cell in a column which changes in length. In this case, I would like to reference the most current date in a column. Is there a simple method for doing this, as the data will routinely be different lengths in that column. Further, there is Data on the Horizontal that I would like to reference to another cell in another sheet that would correspond to this date. Can anyone give any suggestions as to the best way to accomdate this?
View Replies!
View Related
Create Array Of File Names/sheet Names
Two part question: 1) I'm relatively new to arrays, but what I need to do is generate a list of file names and the sheets within each one. I would like to use an array for this, but since I don't have much experience.... well....that's why I'm here. Can someone point me in the right direction? 2) And the second part of this.... I was planning on using the FileSystemObject to determine the files in a selected folder and loop through that list of files, opening each one and harvesting the required info (file name and all sheet names). Should I use the FSO or is there something built into Excel that might be better (and also limit the number of dependencies for this little "project" of mine).
View Replies!
View Related
Find Method Code: Object Variable Or With Block Variable Not Set
I need my program to: - find the cell containing the string "Datum/Tid" - record the column and the row of the found cell in two variables lCol and lRow Here is my Sub test() Dim rFoundCell As Range Dim lRow As Long Dim lCol As Long 'Find method of VBA Set rFoundCell = Range("A1") Set rFoundCell = Worksheets("Sheet1").Range("A1:Z50").Find(What:="Datum/Tid", After:=rFoundCell, _ LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByRows, _ SearchDirection:=xlNext, MatchCase:=False) 'for anyof the two lines down I get the message "object variable OR block variable not set" lRow = rFoundCell.Row lCol = rFoundCell.Column End Sub
View Replies!
View Related
Referencing Sheet Tabs
Is there a way to use the "value" of a name in a drop-down list to reference a sheet tab name in a formula? A1 has a drop down list. When a name (Bob's Sales) is selected from the drop down list, B1 shows the value of cell D5 from sheet "Bob's Sales".
View Replies!
View Related
Referencing A Sheet From An Inputbox
I have a quick question that'll hopefully have a quick answer. Part of my workbook requires an input box to appear. When you type the name of one of the worksheets into the box and hit enter I want a VLOOKUP formula I've written to compare to that worksheet. Heres what I mean, with some descriptions of what i would like:
View Replies!
View Related
Referencing Another Sheet In Same Workbook
I have two sheets in the same work book and I want to pull values through from one to the other. So its a simple =Sheet2!B45 or whatever yeah? But no! What Excel 2007 does when I hit enter is to swap the Sheet!2 bit for "C:documents and Settingsmy documentsspreadsheetsmyworkbook!Sheet2!B45" or some such. Why the hell does it do that and how can I stop it.
View Replies!
View Related
Referencing Cells In Another Sheet
I need assistance referencing cells in other sheets. I have a summary tab which I would have each refenced sheet listed (named for the activity being billed). In a separate cell in the summary tab, I want to bring back the value of the total amount billed for that activity. The total value is in the same cell of each sheet, as all invoice tabs needing to be referenced are identical in layout. There is one hitch to this, the sheets referenced have not yet been created (that would be too too easy), and the activity list in the summary sheet has place holder names that will change when the activity being billed is defined (hence prompting the biller to create the sheet to be referenced).
View Replies!
View Related
Vba Sheet Referencing
I have 8 sheets, named cpt1 to cpt8 in vba. Now i need to loop through these 8 sheets, storing the same range of each sheet into a matrix. I have the following dim test () as variant For i = 1 to 8 (1) test = sheets(i).Range("b2:u21") (2) test = cpt1.Range("b2:u21") next i Now (1) doesn't work, but (2) does. However i do not know how to reference the cpt1 sheet name using the for loop (ie "cpt" & i) Can anyone help me with getting this to work?
View Replies!
View Related
Concate Variable Names Using VBA
Here is the code loop that I have so far For Each Dn In Rng If Not .exists(Dn.Value) Then .Add Dn.Value, "" End If Next Dn I want to declare a varaible called peg and then for each Dn assign it to peg so in the end for each Dn I should have peg1, peg2, etc, etc. Each of these should have a default value of zero that I will later modify.
View Replies!
View Related
Setting Variable Names In Vba
I am working on a macro for excel which has a userform where the user puts in the number of samples they have, then takes them to a new userform to input the weights of the samples. I want to be able to set the sample mass variable dynamically based on the number of samples they have… i.e. spl1 spl2 spl3 . . . splx x=number of samples This number will be different each time so I am stumped at how to do this since I have just started in vba and do not know too much yet.
View Replies!
View Related
Declaring Variable Names Dynamically
Is it possible to declare n variable names dynamically in a macro? For example: Cell A2 in Sheet1 contains the number of variables to be considered in the macro (n). I would like all the variables to take names in the macro from node1 to noden using the dim statement. I tried running a for loop:
View Replies!
View Related
Formula Referencing Previous Sheet
After a formula to copy the contents of a cell in the previous sheet in a workbook, so that if I was to copy the last sheet in a workbook the formula would automatically reference the cell from the copied worksheet and so on if I copied tht one. Hope this makes sense I have a lot of formulas referencing the previous sheet and everytime I copy this sheet to create a new sheet I have to change the sheet number in the formulas. eg, in sheet 8 this formula get info from sheet 7 cel J30 ='7'!J30 when i copy the sheet to create a new one (Sheet 9) I would like the new formula to automatically be ='8'!J30.
View Replies!
View Related
Vlookup - Referencing Sheet Index
I am trying to find out whether it is possible to reference to a sheet index number, instead of sheet name, in a VLOOKUP formula. For instance, normally I would write: VLOOKUP(A1,'ExampleSheet'!A1:B10,2,False) (I hope got the translation to English language Excel correct) Let's say that the sheet index of Examplesheet is 2 (at least it is 2 the way VBA sees it). Is there a way I could reference sheet number 2 in the VLOOKUP formula, instead of its name? My sheet names vary, but the formula should look in the same area, regardless of name.
View Replies!
View Related
Referencing Cells Dependent On Sheet Name
I have a workbook that has a number of sheets with various project stages and dates on them. These details are arranged in small tables displayed vertically down the page. Each worksheet's name is the project code - e.g. 30033_99 I have now been asked to create an overview page that displays all these stages and dates on one page. What I'm trying to do is get Excel to look at the column with the project code and then pull information from the worksheet with that name.
View Replies!
View Related
Open Multiple Workbooks With Variable Names
I have data spanning many files which are named with the date on which they were created (so there are 31 files for August). For example: PL080107, PL080207, PL080307, PL080407...) I'm trying to compile all of my data into one workbook, and have the macro to append each file to a list. Now I need the macro to either OPEN each file, or ACTIVATE each file so that the rest of the Macro can grab the necessary data. I say Open or Activate, because I can MANUALLY Open a full month's worth of files if it's easier code. If not, I would like it to open and close each workbook on its own. I have over 7 month's worth, so opening 31 files 7 times is better than opening over 200 files individually!
View Replies!
View Related
Recognize Text Values As Variable Names
I want VBA to take an equation that has been entered into an worksheet cell as text and evaluate it. Here's a very simplified example that shows the concept: Cell A1 may contain the text: "A * B + C" I would like to do something on the order of this in VBA: Sub Test() Dim A As Integer, B As Integer, C As Integer A = 2 B = 4 C = 6 MsgBox Evaluate(Workbooks("Book1").Sheets("Sheet1").Range("A1").Value) End Sub Obviously, this doesn't work, but I want it to show a result of 14. The actual situation is much more complex, but it all comes down to being able to evaluate the text in a worksheet and recognize the variable names that are in it.
View Replies!
View Related
Referencing Cells From Another Sheet, Dealing With Blanks
I have a sheet which I want to populate from another sheet within the same workbook. I am using the following, where Data = original worksheet, T2=cell to be displayed: =Data!T2 When i do this for the whole spreadsheet, where there are blanks it is entering "0" or in the date fields, 01/01/1900. Is there any easy way of defaulting them to be blank if there is no content in that cell?
View Replies!
View Related
Referencing Active Cell's Value From Another Sheet
I'd like for users to click in a cell in col A in a sheet named "Period7", have the cell value placed in cell C11 in a sheet named "Per7Report," and change the focus or active sheet to sheet Per7Report. Can this be done simply by clicking in a cell, or must a command button be inserted into each cell (note - odd rows only) in col A in Period7. on the code to do this? Note that there is a formula in col A in sheet Period7
View Replies!
View Related
#REF! Error Referencing Worksheet After Importing Sheet
I have a template i'm making that is full of formula references to sheets not yet in existance in the workbook. what i want to happen is this: My code imports data files, renames the tabs to 1, 2, 3, 4... The formulas i already have are set in the CONCATENATED tab.... an example of such a formula is: ='1'!$P2. so this should work, and yet it doesn't. the sheet is imported as it should be, the tab is renamed to 1, and yet the CONCATENATED sheet still shows #REF for the cell value. if i click in the cell, click in the text bar and enter out, the formula updates. there apparently is no option that i KNOW OF (although i'm sure there is something out there that does...) that will update this without me entering into the text bar and entering out. Question: how do i manually update all references once the sheets to those references have been imported?
View Replies!
View Related
Summary Sheet Of Sheet Tab Names
I’ve had a look through the forum and on some of the guides/FAQ but thanks to my ineptitude I have been unable to adapt any of the examples to my specific situation. What I’m after is this: I need to create a summary sheet for a work book with a variable number of tabs. All I need the summary sheet to do is to make a table of the name of the tab and then cell A17. How would I go about doing this and is it possible to save this macro to my machine/all workbooks instead of just the one?
View Replies!
View Related
Referencing Selected Tabs To Print Selection & Update Table Of Contents Sheet
I searched but didn't find exactly what I needed. I have a workbook with 31 sheets. It is a price guide with each category on a separate worksheet. I figured out how to list the sheets on a separate tab. What my client wants is the ability to: 1. select certain categories for printing, the ToC, Cover and backcover pages have to print in every case 2. the ToC has to change depending on the sheets selected. I'd rather write some code and give him an an easy command button rather then teaching him how to select non-concurrent sheets and printing only active sheets. What I'm really stuck on is the updating of the ToC with active sheets only (category and starting page which changes depending on pages selected).
View Replies!
View Related
Conditional Formulas-to Get A Spreadsheet To Automate Calculations Of Unit Costs Based On Variable Packaging Names
I am looking for a way to get a spreadsheet to automate calculations of unit costs based on variable packaging names. I have a series of packages that are denoted by text phrases. Examples: 4/6/12 2/12/12 6/4/12 18/12 24/12 For our purposes let's say the package names above will always be in column A. Column B contains the frontline price of a case of product represented by the phrase in column A. Column C will contain the cost per unit of product - this is obtained by dividing column B by the number of each package arrangement that can be found in one case. Most of the time the number of package arrangements per case is denoted by the very first number in the package name (ie, 4/6/12 would be 4). This won't always be the case though (18/12 would be a package arrangement of 1). I am looking for a way for the spreadsheet to do all of the following and return the results in column C: if the package name contains "4/6/12", divide column B by 4; if the package name contains "2/12/12", divide column B by 2; if the package name contains "6/4/12" divide column B by 6; if the package name contains "18/12", divide column B by 1; if the package name contains "24/12" divide column B by 24.
View Replies!
View Related
Code To Update With Names From Ranges
I need my SQL server query to update with names from a range. e.g. pinnog as shown below is a name defined range called Name1 and smithb will be Name 2. Can someone with me with this code as I am not sur ehow to lookup ranges in VBA. My code is below ...
View Replies!
View Related
Parse Worksheet Names Directly In Code
I am trying to add new worksheets at the end of the existing ones, with the name "Scenario " & i (i being an integer for the next scenario). My idea is to parse the Worksheet names, counting how many times the string "Scenario " appears, and then add a new Worksheet with that name and index i+1. Here is the Public Sub store_data_Click() Dim NameWS, prev_sheet As String Dim iprev, iws, iscenario As Integer iscenario = 1 For iws = 1 To Worksheets.Count If Find(Sheets(iws).Name, "Scenario ") = True Then iscenario = iscenario + 1 End If 1.- Find (8th line) does not seem to be the right procedure to use; how could I do this in a clean/direct (i.e. not writing the names into a dummy worksheet and using the find function) way? 2.- How could I substitute the new Worksheet ("Scenario " & i) formulas for values without having to select all the cells and then use paste values (not so elegant). 3.- Connecting to a previous post: How could I define *exactly* the position to paste "Autoshape 1"?
View Replies!
View Related
Run Code On Worksheets With Certain Tab Names
My Thread title should have read covert code TO run on all worksheets with same word in Name. I have had a look at some other pieces of code in this forum but they are quite the same as I want to do....I have tried a few things but each time I get an error ...so for sure I am not modifying the code quite right, I ahve been missing something for what I now want it to do. So I wonder if someone could Please review these two pieces of code...they of course are both for running on just one worksheet in a wookbook. I would like them both be able to run, still as tow separete pieces of code as they are, on all and only worksheets that have in their worksheet name a key word in this case the word "Region" and that those worksheets all in a single workbook but the workbook does have other worksheets in it I dont want the code to run one on - but those worksheets do not have in their worksheet name the word "Region". Sub test() Dim r As Range, txt As String, ws1 As Worksheet, i As Long Set ws1 = Sheets(1) With CreateObject("Scripting.Dictionary") .CompareMode = vbTextCompare For i = 16 To 21 Again: For Each r In ws1.Range(ws1.Cells(6, i), ws1.Cells(Rows.Count, i).End(xlUp)) If r.Value <> "" Then If Not .exists(r.Value) Then .Add r.Value, Nothing Else txt = txt & "," & r.Address(0, 0) If Len(txt) > 245 Then ws1.Range(Mid$(txt, 2)).EntireRow.Delete txt = "": .RemoveAll: Goto Again End If .............
View Replies!
View Related
Delete All Range Names Macro Code
I have written VBA code which is operated every month. This code deletes several range names in a target spreadsheet, performs other actions - including extracting certain areas to different spreadsheets and then closes the spreadsheet without saving. The range names in the target spreadsheet are required for ongoing use, so can not be deleted permanently. Is there any code that deletes all range names in one go? At present my code includes the results of recording a macro wherein I delete each range name in turn - creating script over 100 lines long.
View Replies!
View Related
Look Up Sheet Names
In Column A row 4 of sheet1 I have an account name, for example Sonic, and I have a sheet named the account name, Sonic. In Column B row 4, of sheet1, I would like to return the value in Column B row 3 in sheet named Sonic, or the account named sheet. I have about 50 different account names along Column A in sheet1, and the same account name sheets opened in the same workbook. Is there a good formula or vba code that will work for all the values in Column A of sheet1 to look for the same named sheet and return the values off of that? Note: on the account sheets in Column A it says ‘Account’ for all of them.. this wasn’t a mistype
View Replies!
View Related
VBA Code- To Pull All The Names Of The Worksheets In A Workbook
I just started playing with creating my own macros. I've written a macro to pull all the names of the worksheets in a workbook, now what I want to do is write a piece of code that will pull data from a cell in those worksheets. So for instance I have all my worksheet names in cell A1 to A10, I want to pull the data from cell E1 from every worksheet in A1 to A10. Can someone help me with a sample code to work with. I'm still reading Power Progamming haven't gotten so far yet.
View Replies!
View Related
Formula Containing Sheet Names
I have done a formula for Abbott as shown below however I actually have about 50 sheets with names. I have the names listed in column A. Is there a formula that instead of typing Abbott as shown I can use the cell in column A to generate a code ?
View Replies!
View Related
Duplication Of Sheet Names
I made a macro that will name the current sheet whatever text is found in cell B2 on that sheet. This works great unless that sheet name already exists. If the sheet name already exists, is there a way to rename it as Cell B2 plus the number 2 after the title so it doesn't cause an error? Example: "Smith, Bob" is a sheet name, so the macro would make the new sheet name "Smith, Bob 2" Alternatively, how could I give a pop-up telling about the error and deleting the current sheet instead of renaming it with a "2"? Eample: "Sorry, 'Smith, Bob' already exists. Deleting new sheet." as a popup and have it delete the current sheet.
View Replies!
View Related
Change Sheet Names
I have got a workbook with about 200 sheets... Sheet1 > Sheet200 i need to delete about 100 sheets... sheet100 > sheet200 i then need to add the sheets back in but when i do the sheet numbers start from Sheet201... how do i get it to start from Sheet101 again or can i use some vba to change them later?
View Replies!
View Related
|