I need to creat a bunch of sheets and do the same work for each of the sheets. My problem is that I do not know how to refer them by the created name. Here is an example of my codes:
Dim I As Integer
For I = 1998 To 2010
Sheets.Add.Name = I
The error is "Subscript out of Range". I believe it is because when I refer a sheets(I), (I) does not recognize as the name of the sheet but the number of that sheet, and there is no sheet numbered 1998 or bigger. However, If I refer the sheet as sheets("I"), it can not find the sheet named "I" either.
How should I refer those sheets name so that I can do some work?
I have the following code that creates a new workbook and names it after the value of a cell in another workbook. Another part of the macro will switch back and forth between the original workbook and the newly created workbook.
What is the best way to refer to new workbook? I'm familiar with the "workbooks "VARIABLE NAME".Activate" style but, the name of the new workbook will change every time the macro runs and I'm not sure how to refer to it.
the code below.
HTML Code: Sub MakeNewBook() Dim wB As Workbook Dim nPath As String
A2 refers to a linked cell but I have tried without the link there still no joy. Together they would generate for example "DCA_RES" which would refer to a column range in a different sheet on the same workbook.
I want this to work so that I can implement more easily new lines to refer to different sheets. (Drag to copy) instead of having to copy and edit a formula 100 times.
I've been referencing sheets in my code directly with things like
however in recreating a new workbook (to reduce bloat), the sheet-numbering has changed... to avoid having to mess around adjusting things again, I was wondering if it's possible to do some sort of indirection... something similar to
I have a workbook with three sheets: Collections, Client and Interest New sheets created from a range in Sheets("Interest"). The range in Sheets("Interest") holds the client names.
Then the template in Sheets("Client") is copied and pasted into the new sheets
For each new sheets cell B6 holds the client name and .Range("A10:A1317") holds the dates Sheets("Collections").Range("D10:D1317") holds the dates and .Range("D8:WC8") holds the Client Names if Sheets("Collections").Range("D8:WC8") = new sheet.cells(6, 4) then if Sheets("Collections").Range("D10:D1317") = new sheet .range("A10:A1317") then copy the value in Sheets("Collections").Range("D10:WC10").offset(0, 3) to new sheet .Range("C10:C1317") end if
How do I tell a loop command to stop after a certain number of sheets? The code below works for what I want to do but it saves all the sheets in my workbook bar the first one. I just want to save sheets 2, 3 & 4
Code: Option Explicit Sub mysaver() Application.Calculation = xlManual Dim counter As Integer counter = 2 ' counter is for the number of sheets in the workbook Do While counter
I have a small macro that searches the sheets in a workbook and sends the info (if qualifies) to a new workbook before saving that workbook using a name date time format for records.
I woud like this macro to be able to repeat action in 8 more selected workbooks in a folder. Question - can I name the workbooks I want to search - and - can I search all 9 workbooks before the data sheet saves and names itself, limiting access.
I have this very simple code below that I use to delete a row if its marked as 'false' in column M. This works quite well, but I want to expand it. I use this in a workbook that can have name different sheet names in a month, and I want it to automatically go through all the sheets and do this...except for 2 sheets named addressess and sheet1. Is there something I can add to this macro that will loop through all the other sheet names (regardless of name) and execute this?
Sub DelRow() With ActiveSheet .AutoFilterMode = False With Range("m1", Range("m" & Rows.Count).End(xlUp)) .AutoFilter 1, "false" On Error Resume Next .Offset(1).SpecialCells(12).EntireRow.Delete End With .AutoFilterMode = False End With End Sub
I am trying to loop all columns in each of a number of sheets using current region.
It selects the current region OK but the column counter only shows 1 as the number of columns in any sheet.
The Cells(6,1) likely has something to do with it but I do not know any other way to point to the current region I need. I do not know in advance how many rows or columns I am starting with but each has the required Row 6.
I have a workbook with 180 Sheest. I need to copy sheet name and paste to column Name. In the Column Year write 2013.Finally I need to all sheets as show below in in Sheet Farms. Doing this one by one is time consuming and with error risk. I think a loop can do this,nevertheless, I don't Know how to do it. Column size can be different in each Sheet
Sheet name Famr1 CodNameYearDescTotal1Total2ProvCnt 1234Apples200xxxyyyzzz 3412Bananas400xxxyyyzzz 2358Oranges500xxxyyyzzz 8956Pines800xxxyyyzzz
However it will only add data to the active sheet when i am asking it to loop through the workbook missing out specified sheets. Would anyone be able to look over the code to see where the error is as to why it will not loop through the remaining sheets in the work book.
I am trying to loop a procedure that changes a cell value on 2 sheets in a workbook. I recorded a macro on one workbook and it worked fine. I then tried to modify the macro to loop this on more workbooks that have identical worksheet names. The macro is in a workbook named LIST, which column A has a list of all the workbook names. Currently there are 55 workbooks, but in the future I am sure there will be a few more. Here is a copy of the macro:
Sub Macro1() ' ' Macro1 Macro ' Macro recorded 5/28/2008 by MT ' Dim STATEstr As String Dim a As Long a = Range("C1") For STATEstr = A1 To A55 Workbooks.Open Filename:="C:ALLSTATES" & STATEstr & ".XLS" Sheets("3 ANL").Select Range("A1").Select ActiveCell.FormulaR1C1 = a Sheets("3 ANLV").Select Range("A1").Select ActiveCell.FormulaR1C1 = a ActiveWorkbook.Save ActiveWindow.Close Next STATEstr End Sub The first error I got was a TYPE MISMATCH on 'For STATEstr = A1 To A55'. There may be more things wrong with this looping. The only experience I have with macros is recording them and then modifying and combining them.
Col A: Date Col B through M: Headings are employee names, data is how many hours of vacation per DATE.
User will enter a date in column A, and then the corresponding number of vacation hours a person took that day. There are a dozen or so employees, so we're only entering a record on the dates that someone has taken vacation time. Dates are mm/dd/yyyy format. The hours are number/two decimals.
What I would like:
An update command button (hey, I can actually do that part!) that has an on-click that:
Loops through each column B through M, and copies the information to the employee's individual sheet.
The individual sheets:
Columns are: A = Date of vacation B through M are months Jan through Dec.
Data starts *paste* in cell A12, where the date of the first vacation day they take should appear. If it was a half-day in February, .5 (or .50) will appear in cell A14.
If it's not clear, I'm happy to send the file! If you put your email here, I'll send it right away. If you email me at home, it'll be a few hours before I can send.
No rush on my part.
Really appreciate it!! I'm not a coder. I know small bits and pieces. When you start talking about Dim, I think of chinese food.
[ This Message was edited by: Dreamboat on 2002-04-11 10:20 ]
I've started building a macro that loops the sheets and collects the information onto the first worksheet. I've been using Activesheet and activecell references but i'm afraid looping will change these references.
Notice that there is an empty cell in between.The data starts at C12 up to C21. The data is in Sheet2.There are also 8 more sheets( Sheet3 to Sheet10). I want to rename each sheet, starting from Sheet3 according to each cell. For example the Sheet3 to be renamed to 01, Sheet4 to 02.
What I can do is something like this:
And repeat this code for every block of data I got by changing everytime the i and the a. But this method is not so optimized because there are cases that the number of rows for each block is not the same and I have to change everytime the i counter. Is there any way to do 1 loop for all the sheets using maybe Worksheets.Count and another dynamic loop for the rows ? The data always start every 6 rows eg( C12, C18 etc). Also I was thinking to define an integer representing the number of rows for the loop...
writing a loop that will perform the same action on 11 worksheets but stop if it gets to a sheet with no data in cell A1. The data in A1 will be text. The code I wrote below below does what I want it to, but I have to run it on each individual sheet.