Refer To Workbook With Name That Is Created By Macro?
Sep 28, 2011
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
[Code]....
View 3 Replies
ADVERTISEMENT
Oct 16, 2007
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:
Sub test()
Dim I As Integer
For I = 1998 To 2010
Sheets.Add.Name = I
Sheets("Number").Activate
Range("A1:A3").Select
Selection.Copy
Sheets(I).Select
Range("A1").Select
Selection.Paste
Next I
End Sub
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?
View 7 Replies
View Related
May 16, 2011
I have to excel files, both have the same data. I created a pivot table macro on the first file. I want to be able to open the second file and use the shortcut to create the pivot table. the problem is that it refers back to the original workbook I created the macro on. How do I change the code to make it refer to the current workbook?
Code:
Sub Pivot()
'
' Pivot Macro
[Code]....
View 1 Replies
View Related
Jul 4, 2014
I am creating 4 Sheets from a Main Sheet by Filtering Data based on different values in a fixed column, then the Filtered Rows are automatically pasted in the respective sheets.
Then these 4 Sheets are creating another file.
The same thing done manually by Grouping the 4 SHeets and then Move Copy into a New workbook also makes the file heavier.
Everything works fine however though the data is not much the file is very heavy, so what do i do to make it of appropriate size ?
View 1 Replies
View Related
Mar 7, 2014
I have a workbook with macro button to run some vba, if i want the button to disable when the user make copies of the workbook (date created is later than original wb saved time) what codes to add in the VBA?
what i assume is to add the time to a cell when the wb is saved, when the wb opens, it check for that cell if the same with the date created, if different, then disable the macro button.
View 9 Replies
View Related
Nov 9, 2009
I'm using this code to open another workbook:
Dim FileToOpen
FileToOpen = Application.GetOpenFilename _
(Title:="Please locate BlankSAMSRegister.xlsm", _
FileFilter:="BlankSAMSRegister.xlsm (*.xlsm),")
If FileToOpen = False Then
MsgBox "No file specified.", vbExclamation, "Error"
Exit Sub
End If
Once this second workbook is open, how do I refer to each one within the subsequent code?
I really need the parent workbook to be named as wb1 and the child to be names wb2 so I can flick between the two in the next macro... I can get the parent using thisworkbook.name, but how do I get the child?
View 9 Replies
View Related
Apr 17, 2009
I want to be able to safeguard against a user changing the name of a worksheet, so I use the sheet's codename in all my macros.
I have the codename of a sheet: shOptions
From a different workbook, "ActiveWorkbook.shOptions" doesn't work. How can I use "shOptions" in the other workbook.
View 14 Replies
View Related
Jan 29, 2010
At the moment, I have a project where everyone is putting work data on seperate workbooks. Each months work is placed onto another worksheet within that workbook.
The supervisor has his own workbook, that grabs data from each of the workers books. Getting the data is easy enough, however because the supervisor has barely any knowledge of computers, I would like to make it as easy to set up for future months.
Right now, data is collected in each cell using the following formula:-
='[otherusersworkbook.xls]December 2009'!$C$620
Is there a way of getting that phrase to substitute the part that says "December 2009" with whatever is put into column A on the same row?
View 3 Replies
View Related
Mar 25, 2014
I've created a macro which copies the current tab to a new workbook (Book X):
[Code]....
I then manipulate the copied data in Book X. Once this is done I move the manipulated sheet back into original file
[Code] .......
The problem i'm having is I'd like to close the newly created Workbook X file once the macro has run but Workbook X is usually called Book2, Book4, Book7, Book32 etc.
Workbook X will always be the previous file if i use the ALT TAB shortcut.
View 2 Replies
View Related
Oct 27, 2006
I've created an add-in that runs a simple macro. The problem I have is that when I run the add-in it opens the workbook I originally created it from - is this what I should expect it to do? How do I stop this from happening?
Also, do I need to have the workbook from which I created the add in located in the same place on every machine I want to use the add in on? At the moment if I move the original workbook the add-in won't work.
View 9 Replies
View Related
Nov 7, 2013
I have created a spreadsheet that I wish to save as a template. However, when the a new workbook is created from the template it needs to be saved as a Macro Enabled workbook not just a workbook which is the default. To achieve this I added the line 'thisworkbook.FileFormat=xlOpenXMLWorkbookMacroEnabled' to the 'beforesave' macro for the workbook. This works fine except that it makes saving the file as a template quite difficult.
How I can trap the first time a workbook created from a template using New is saved would be most useful.
View 6 Replies
View Related
Sep 22, 2006
I am having trouble getting a copy of current workbook to save (with a hopefully unique name) into a vba created folder. The folder creates fine on any drive that I have access to, but the workbook never turns up. The code is only an extract from the whole but it still fails in isolation.
Sub Macro1()
Copyit:
Dim fso
Dim fol As String
Dim flag As String
fol = "E:Excelb4macrobackups" ' change to match the folder path
Ans5 = MsgBox("Create Backup of " & ActiveWorkbook.Name & "?" & vbCrLf & vbCrLf & " Backup File Path:" & vbCrLf & vbCrLf & fol, vbYesNoCancel + vbExclamation)
If Ans5 = vbNo Then Exit Sub
If Ans5 = vbCancel Then MsgBox "Procedure Terminated!", vbExclamation: Exit Sub.........
View 2 Replies
View Related
Jun 18, 2009
I am trying to have the user hit a button and save the workbook in a newly created directory. Currently it creates the new workbook and the new directory with the correct names, however the workbook is not in the newly created directory.
View 5 Replies
View Related
Jan 22, 2009
I have a Workbook that is located in a Networked Folder and is used by several people every day. The Workbook has a lot of VBA and also has links to other workbooks. I am noticing that over time there are several extra files being created from this excel workbook, in the same folder. The Workbook is the only file in this folder. They are not associated with any program and are just a File Type. They are titled a series of 8 random Letters and Numbers and range is size from 700 KB to about 1 MB (Slightly smaller then the Workbook file size).
Also, Is possible to automatically delete these files when they are not needed? or better yet is there some way to Prevent these files from being created in the first place?
View 3 Replies
View Related
Aug 9, 2008
My code in the first workbook generates a new workbook with a variable in the filename, then copies the cells from the first workbook to the newly created workbook. This code is working properly when used in a draft worksheet I use for testing. As soon as I put it in the master file, an error message pops up "Runtime error 1004 : select method of range class failed". Then the debug sends me to the line " Cells.Select ". What should I be looking for, why does my code work on one file but when i put it in another one it doesn't ?
Private Sub CommandButton1_Click()
Dim line_counter As Long
Dim prm_line_value As Boolean
prm_line_value = False
Do
prm_line_value = Sheets("Rate").Cells(1 + line_counter, 1).Value
line_counter = line_counter + 1
Loop Until prm_line_value = False
line_counter = line_counter - 1
Dim Wk As Workbook
Dim number_of_new_wb_needed As Integer
If line_counter < 5000 Then.....................
View 3 Replies
View Related
Aug 31, 2007
macro which can paste the value from A1, to another B1 and when A1 is edited again, pasted it in B2. This will probably go on and on until B30. I have tried the if else then in Macro, and even the if elseif, but both don't go futher than B2. E.G A1=1 B1=1 A1=4 B2=4 A1=3 then nothing happens to B3. If there is a way to make this work, it will be great. The way i am tryin to get it is to have =if(B1="","",1) for each cell from C1:30 and with C31 the formula "=count(C1:C30)+1". Then i formated C31 to a custom and make it so that before numbers, there is an B. This means that if B1,2,3 and 4 and numbers in them, then C31 will read B5. That will be the cell i want my next record to go. I would prefer it if there is just a code that i can enter that will go to the next cell when it knows the current cell has a digit in it but if i have to, the count way will do,
View 9 Replies
View Related
Feb 17, 2009
I want to write a formula that inserts a column and then does a vlookup in that new column using the cell just to the left of it as the first variable. The problem is, this could be in any random column so I can't do a static reference to $A2 as an example. So, my question is...
Instead of using =vlookup($A2,Sheet1A1:B50,2,false)
How do I replace the $A2 part with some code that says, "the cell to the left of here..."
View 7 Replies
View Related
Aug 11, 2014
I have the following macro set up to create a folder in a directory as per the contents of 2 cells
C2 = Folder name to be created
B2= Date for previous working day
[code]....
I then have another macro that moves files into a specified folder within the same location ( I then manually move them into the folder the first macro created)
Is there a way I could get the files to move to the newly created folder without me having to do it manually.
View 4 Replies
View Related
Aug 14, 2014
I've got a macro that I can rund when I click on a shape. It's called "Shape_Click".
Basically, I want this macro to be automatically assigned to any shape I create, as I create it.
I know the line will be something like: [Code] ........
View 6 Replies
View Related
Aug 14, 2014
I have a macro that runs when I click on a shape. This macro is called "Shape_Click"
I can apply that to a shape by selecting it and manually running this macro:
[Code] .....
How do I get the subroutine to run as soon as the new shape has been selected, rather than haviong to manually run it.
Something like "Sub Worksheet_ShapeAdded" or something like that? I can't work it out.
View 2 Replies
View Related
Jun 12, 2008
I am working in a macro that will do some calculations and I would like to end it by plotting the results in some charts. Results are in one dimension array form, with probably more than 1000 elements. Can anybody tell me if there is any limit for the arrays that are going to be asigned to the XValues and Values of the chart?
View 14 Replies
View Related
Apr 1, 2008
I have 100s of name ranges in my spreadsheet. I am using a series of drop down boxes for the user to select the info that they want to see. Based on the dropdown box, the macro "dynamically generates" a range name from which to pull the info.
For instance, if they Select Manager = Terry, Analyst 1, and Month = Jan, then the range name would be JanTA1
The if statement would dynamically create this name by concatenating the info
If manager = Terry
mnger = "TA"
if analyst = 1
anlyst = 1
if month = Jan
mnth = "Jan"
rangename = mnth & mnger & anlyst
So, I am dynamically creating the range name based on user selections...then to display it, I want to set the display cell = to the value
Range("display cell").Value = Range(rangename).Value
The problem is, I am getting an object error every time I try to refer to a range this way.
If I type:
Range("display cell").Value = Range("JanTA1").Value, it works
View 9 Replies
View Related
Mar 13, 2007
On a sheet, I have a Worksheet_change sub that checks if the cell changed is in column 1, 10, or 19 and if it is, then the six cells to its right are filled with formulas I need. All formulas work, except for one. I've checked over and over again and the formula itself works fine - the coding behind it is exactly what it's supposed to be.
But for some reason sometimes the formula isn't put into the cell. I haven't found any pattern yet with this problem. Even stranger is that the formula is identical to one in another column before (which is also entered by the macro) and the other one has never disappeared yet. I'm setting both formulas with the abc.FormulaR1C1 property (I don't use the abc.Formula property to avoid having to write three different formulas - one for each possible column change).
View 3 Replies
View Related
Jul 4, 2014
I am completely new to Macro's and VB and the macro below has been generated using the "Record Macro" function in Excel 2013 with a couple of very minor modifications based on some research I have done (hyperlink & input box). My ultimate goal is to make a copy of my "TEMPLATE", which is hidden and the copy could have a variety of names, then create an entry in my "SUMMARY" table that references cells on the newly created sheet. The new entry on the SUMMARY page should be entered in the next available row ... at the moment I need to make sure I have my cursor in the right place before I run the macro. I also want the first cell in the new "SUMMARY" row to create a hyperlink to the newly created worksheet.
The macro does what I need it to do, as long as I name the new sheet "Test", what I would like is for the Macro to recognise the name of the new worksheet and create links to that name. The rows and columns in each new sheet will remain the same, hence the R##C## part will always work.
The "SUMMARY" and "TEMPLATE" worksheet names will not (ever) change.
View 4 Replies
View Related
Feb 12, 2014
I am trying to write a simple macro to copy a drop down list I created in cell O2 and then paste in the same sheet. I need it to paste starting in cell A2 and then move to A4 and so on for every even row cell through A9778. I would also like it to keep a border around the cell. I can't find direction on how to tell it every even cell or defining x and then doing x + 1...
View 3 Replies
View Related
Mar 5, 2008
if it is possible to write/record a macro that will automatically add a summary/total row immediately below the data that is created from an advanced filter. (XL00)
View 12 Replies
View Related
Aug 10, 2007
I've been working on a macro that opens me up to a certain path so I can select a file.
This is the path sofar:
TheFile = "\datawhse
ootLAW81LAWSONprintRBLEVINS2anrvwfins1"
My code takes me there, but I want to go a step further if it is possible.
\datawhse
ootLAW81LAWSONprintRBLEVINS2anrvwfins1THE NEWEST CREATED FOLDER"
View 9 Replies
View Related
Apr 10, 2009
I have created a form that pops up using a macro when the form is opened. It is a simple form that uses optionbuttons in a group to select Intl or Dom.
Problems:
1) How do you get the form to close once a button is selected?
2) The user can close the form without selecting a button (the X at the top).
3) How do you get the data selected onto the excel spreadsheet?
View 9 Replies
View Related
Jan 1, 2008
I have a sheet that I will activate by clicking on the tab.
In that sheet I have a code Worksheet_Activate / Call Summary / End sub
The problem is that the macro Summary this sheet get deleted and a new sheet
created,so I can use only one time this Worksheet_Activate.
View 9 Replies
View Related
Dec 7, 2012
Here's my macro:
Code:
Sub CopyRow()'
'Copies row to new sheet, highlights it, marks column 'A' as copied.
'
Dim cCell As Range
Set cCell = Selection.Cells(1, 1)
Selection.Copy
Sheets("Sheet2").Select
Rows("2:2").Select
[Code] .....
Is it possible to modify it to paste into a different workbook called c:filesDestination.xlsm, instead of the existing workbook (Source.xlsm)? The destination sheet name is the same (Sheet2). It's OK if both workbooks are open at the same time.
View 2 Replies
View Related