How To Get Workbook Name From Variable Sheet Name

Nov 11, 2011

I have an Active sheet which is

MySName = ActiveSheet.Name

Here MySName gives the active sheet name.

I require 1 more variable to take this MySName and assign it to a workbook name and make it is as .xls as i required this workbook name to be used later to close the workbook

For ex:
MySName = ActiveSheet.Name

this gives MySName =aaaa

Now i want like MyWBook = aaaa.xls

But aaaa i want it from variable as we cannot hardcode it.

View 1 Replies


ADVERTISEMENT

Vlookup On Different Workbook With Variable Sheet Name?

May 28, 2014

I just started venturing into VBA. I'm trying to pull the data from a different workbook that will have the previous month as the sheet's name. I can't get the dynamic part of the code.

[Code] .....

View 5 Replies View Related

Excel 2010 :: Paste Link Chart From One Sheet Of Workbook To Another Sheet Of The Same Workbook

Jul 20, 2014

I've created a chart in sheet 1 in a workbook. I want to copy and paste that chart into another sheet (lets take sheet 2) of the same workbook. I am using Excel 2010 version.

Whenever, I try to copy a graph and want to do "Paste Special as Link picture". The problem I am facing as "Paste Link" option is inactive.

I am attaching the Excel for your reference.

View 2 Replies View Related

Copying Data From One Workbook Sheet To Another Workbook Sheet Without Overwriting

Jul 1, 2014

The two sheets are...

1. Sheet1.xlsx (regular excel sheet as the extension is .xlsx)

2. Consolidated.xlsm (macro enabled sheet as its extension is .xlsm)

1. Copy both the files on your system under a particular folder.

2. Now make 9 replica's of Sheet1.xlsx and name them as Sheet2, Sheet3, Sheet4, .......... Sheet10

3. Open the sheet Consolidated.xlsm and see the button i have added called "Pull Data".

Now write down the code by adding a Module in that excel sheet from the code window.

4. Write a code that will open each of these sheets (Sheet1, Sheet2, Sheet3, Sheet4, .......... so on) one at a time and will copy the data from these sheets to the Consolidated.xlsm sheet.

5. Make sure that the data is appended(and not overwritten) from the multiple sheets (Sheet1, Sheet2, Sheet3). that is once you paste the data from sheet1 to Consolidated.xlsm then the Sheet2 data will be pasted at the end and after that sheet3 data will be pasted and so on..

6. In this way at the end we will have all the data from Sheet1, Sheet2, Sheet3...in the consolidated sheet.

7. The Division column in the Consolidated sheet will have the value of first row in these multiple sheets. So after making the replicas of Sheet1, please change the value in first row (Range A1) to any other value to avoid the confusion.

8. I have highlighted the data for two sheets in yellow and grey color in the consolidated sheet.

View 8 Replies View Related

One Sheet Saves A Column To The 1st Empty Row On A 2nd Sheet After 1st Looking For A Match On An ID Variable

Apr 2, 2008

I am trying to create a macro so that when i save an entry the form sheet looks in the tavela master sheet to see if there is a match on the record number (in the A column) and saves there as an update if it matches and then if there is no match, saves it in the last empty row. this is a column to row copy so it has to be paste special to transpose. also i have a password on the sheet which i use to unprotect then reprotect. i have successfully done these two things separately but cannot combine them! i know not very much about visual basic code just what i have read here and so i am trying to make this code work.

Code:....

View 9 Replies View Related

How To Specify Workbook With Variable

Mar 3, 2014

I have a spreadsheet where a user inputs a client name (ClientName). I will create a new Workbook with the ClientName along with the current date. 2014-03-03John Doe.xls

I am trying to now input data into 2014-03-03John Doe.xls by specifying it in VBA but I can't seem to reference it properly.

DateStr = Format(Date, "yyyy-mm-d")
Comment = Application.InputBox("Type in Client Name ", "File Name")
WBName = DateStr & Comment
Application.Workbooks(WBName).Sheets(1).Range(A2).Value = "QTY"

But it gives me an error.

View 4 Replies View Related

Set Workbook Variable And Use It Within Another Sub?

May 19, 2014

I have this code which opens another workbook and defines the two open workbooks as MainWkbk and NextWkbk:

Code:
Private Sub wbo()
'open file selected from dropdown on Macros tab and define the two open workbooks
Dim singlepath As String

[Code]....

This works great for going between the open workbooks within the same sub but I also need to be able to use MainWkbk/NextWkbk in another sub within the same module and cannot seem to get it to work!

I tried adding this to the top of the module;

Private MainWkbk As Workbook
Private NextWkbk As Workbook

but this doesn't work, it always says the variable is not set when in the next sub.

I also tried

wbo(Mainwkbk).Activate

within the next sub but this is not right either.

View 1 Replies View Related

Assigning Variable As Workbook

May 15, 2014

So I have a macro that is saving new excel files based on month and year. I want to assign a variable but I keep getting an error.

Here's what I have:

***********
Sub AssignVariables()
Dim Rebates as Workbook
Dim Master as Workbook
Dim month as string

[Code]....

The last two lines are the errors. I want to type in:

Rebates.Activate
Master.Activate

But the error occurs as it gets to the last two lines. By the way, all these two documents are open.

View 4 Replies View Related

Dim Current Workbook As Variable

Jul 2, 2014

I have a Macro that opens a closed file to VLookup some info and pull it to my spreadsheet then close that workbook. the problem I have run into is writing the Macro correctly so if I were to change the file name of the workbook I am running the macro with that it will still use the range declared for the workbook. I have colored the file path that I want to dim in Blue so that it will be easier to see what im trying to do. here is my current macro that works perfectly unless I save my current workbook under a different file name...

Sub Button7_Click()

Sheets("Sheet1").Unprotect "Password"

Workbooks.Open Filename:="\NDGI-SPARE-1UsersownerDocuments2014Vom ResultsVomResults.csv"

Dim c As Range

[Code] .....

View 8 Replies View Related

Set A Workbook Variable As A String

Oct 20, 2009

I have a string variable contacting a file.

I want to set a workbook variable to this file, WITHOUT actually opening it!

ie:
DIM wb as Workbook
DIM filenm as String

filenm = "C: empdata.xls"
set workbook = filenm
============================================

So I know this won't work, but is there anyway around it? (bearing in mind I don't want to open the file!

View 9 Replies View Related

Using Workbook Name Stored As A Variable

Jul 27, 2006

I am opening a workbook using a macro. I need to run a macro in the workbook I am opening when it opens. I have created a variable containing the workbook name but don't know how to use it to run the macro.

Dim WBName
WBName = ActiveWorkbook.Name
Application.Run _
"'DIST_91094_EDTABS_DIABETES CARE_07072006.xls'!aStartProcess"

'DIST_91094_EDTABS_DIABETES CARE_07072006.xls'! needs to be replaced by the name stored in WBName

aStartProcess is the name of the macro in that workbook I want to run.

View 9 Replies View Related

Global Variable For Workbook

Dec 3, 2007

how to set up a global varable over a workbook? Incognito439

View 5 Replies View Related

Set Variable To Worksheet In Another Workbook

Jan 4, 2008

In conjuction with a previous request I've tried to create my own vba code (actually amend existing code i have) but its failing........ whats wrong??

Sub Retail_1_Xfer()
Dim NextRow As Long, Isht As Worksheet, Lsht As Worksheet
Application. ScreenUpdating = False
Set Isht = Worksheets("Retail Team 1")
Set Lsht = Worksheets("Raw Data")
NextRow = Lsht. Cells(Rows.Count, 2).End(xlUp).Row + 1 'next empty row in col A
Lsht.Range("A" & NextRow).Value = Isht.Range("A9").Value
Lsht.Range("B" & NextRow).Value = Isht.Range("A4").Value
Lsht.Range("C" & NextRow).Value = Isht.Range("B9").Value
Lsht.Range("D" & NextRow).Value = Isht.Range("N3").Value
Lsht.Range("E" & NextRow).Value = Isht.Range("N2").Value
Lsht.Range("F" & NextRow).Value = Isht.Range("BJ9").Value
End Sub

I think its got something to do with the fact that the worksheet " Retail Team 1 " is in another workbook

View 2 Replies View Related

VBA Workbook Reference Via Variable

Feb 18, 2008

Ive just finished writing a macro that copies data from different parts of one workbook into a new workbook. However after doing all that my boss now informs me that the first workbook will be renamed regularly.

Is there a way adding a reference to a workbook that is not dependant on the name? Possibly declare it as a variable at the beginning or something? The indexing is not possible either as they might have multiple Spreadsheets open at any one time.

View 4 Replies View Related

Opening Workbook And Assigning Variable

Jul 14, 2014

I am trying to open a workbook, assign it a variable and use that variable later. here is what i have

[Code] ......

When I try to activate it later on in another procedure using:

[Code] copy to clipboard

I receive an "Automation Error"

I have tried declaring it as a public variable, even a global variable and cannot get this to work.

All I'm really wanting to do is open a workbook (where the name will change depending on the book being opened), assign that workbook a variable name, and use it later in the code.

View 7 Replies View Related

Reference Row In Another Workbook With Integer Variable

Jan 28, 2014

I need to reference a different workbook in a while loop. Each iteration, PopFive increases by 3, as I want to pull the numbers of every third row. How does the syntax of the line go after the " ! "?

[Code] ......

View 1 Replies View Related

Assigning Variable To Part Of Workbook Name?

Dec 22, 2011

Ive wrote some code that goes into a workbook. This code then opens up a "master" workbook which has 18 blank tabs in it and then proceeds to open up 18 other named workbooks one at a time and copy some date from these workbooks to the master (i.e workbook 1's data goes to the master workbook on tab "1".)

I have this working no problem but here is my snag.

The workbook name changes every week to correspond with the date (i.e 1_14DEC2011.xls then 1_21DEC2011.xls).

Ideally id like to be able to create a variable for the latter half of the filename so that i can apply this variable to each filepath but i cant quite get it to work.

A small sample of my code is below (and yes i know it is very blunt but so is my knowledge at this stage!)

Code:
Sub collate()
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual

[Code]....

View 2 Replies View Related

Referencing Variable Workbook Tab In VLookup?

Nov 29, 2012

I have a challenge with Vlookups!

I have one workbook called Ratecards, which contains various tabs which are named based on a client code. e.g. ABC02

I then have another workbook which has employees in column B and the client code in C3.

The current Vlookup is =VLOOKUP(B8,'[ratecards.xlsx]ABC02'!$A$5:$N$168,4,false) which works fine for one client.

I want to substitute the ABC02 in the vlookup for cell ref C3, as the contents of C3 is variable and I want it to tell the sheet which ratecard to refer to.

View 3 Replies View Related

Variable Lifetime/scope In A Workbook

Jan 27, 2008

about variable lifetime/scope in a workbook. Basically I have a Class Module that I set up in the Workbook_Open() event as follows:

Private Sub Workbook_Open()

Set CurrentClient = New CClient

End Sub

Once the workbook is open the user can select their "client" and all properties/methods for that "client" are available throughout the workbook until they close it, and it all works fine. However, whilst developing I'm obviously making lots of changes to the code, and every time I do the object is no longer available in memory.

I've tried manually running the Workbook_Open event after I make a code change, and even put in a button with the same code, but whatever I do the object won't remain in memory until I close & reopen the workbook. It's so frustrating having to close & reopen the whole workbook every time I want to test a code change I've made!

View 9 Replies View Related

Value Of A Cell In An External And Variable Workbook

Mar 16, 2008

I need to create a formula or code which will return the value of cell d16 from an external and unopened workbook, where that external workbook's file name, directory and sheet names are provided within cells (able to be updated) of the current workbook. I have downloaded the add-in for INDIRECT.EXT but either being unfamiliar with this function or that I'm barking up the wrong tree all I'm getting is #REF!

And to add to my problem, I was hoping to use this formula / code within an excel table embedded in a word document.

View 9 Replies View Related

Save Just A Variable From Workbook To Disk

Apr 11, 2008

I have a workbook with a field that contains the users name in cell B1. The first time the user opens the workbook, they put their name in this cell. Is there a way that that name can be saved to disk outside of the workbook in the same directory as the workbook is saved and a formula be put in workbook.open so that it will go get this name variable and insert it in B1 so the user doesn't have to enter their name each time.

I now have them putting their name in and saving the workbook which works until I send out an upgrade. Then they have to type in their name again.

View 9 Replies View Related

Pass Workbook Variable Between Subs

Jul 11, 2007

This is the code after editing to make it more clear

Public Sub 1()
BookA= activeworkbook. name
BookB=Application.Workbooks.Add
Workbook(BookB).activate
End Sub

Public Sub 2()
BookB=Activeworkbook.name

With BookB. sheets(1)
.range("A1")=BookA.sheets(1).range("B1")
End Sub()

At the end of public sub 1, BookB is the active workbook. What I want to do in public sub 2 is to copy some data from BookA to BookB. Unfortunately, when moving from public sub 1 to public sub 2, BookA needs to be defined again. The code above is the code that I use in my add-ins. I figured out for non add-ins code I can define BookA with thisworkbook.name when BookB is active as I before work with BookA. This does not apply for add-ins as thisworkbook will refer to my add-ins code. Is there anyway of keeping definition of BookA is constant from one public sub to another public sub? This is simplified code. In fact, I can't merge public sub 2 with public sub 1 due to some reason which I don't say it here.

View 6 Replies View Related

Open Workbook And Assign To Variable

Jul 16, 2007

Back to coding in VBA after long months of Matlab, and banging my head around this simple code snippet:

Sub openfile(FilePath)
Dim myWBk As New Workbook
'Now open Form
myWbk=Workbooks.Open(FilePath)
End Sub

This returns a nasty error "Activex Component couldn't create object". It opens the file given by FilePath though. What I would like is to assign the open workbook to the myWbk variable, such that it is easier to work with.

View 2 Replies View Related

SaveAs - Copy Sheet Into New Workbook And Save It In Same Folder As Original Workbook

Jun 17, 2014

I have been trying to edit a code which previously saved a copy in a new workbook to a specific folder/path. (Additionally it copies and clears some figures, but this is working as it should.)

However I would like the copy to be saved at the same location as the original workbook, regardless of the path the original workbook is saved.

I.e if I need to move the workbook containing the code to a new folder/location, when using the macro, the new copy should be stored in the same folder/location as the original one.

For now it is only saving the copy into "My Documents"

Code:
Sub Macro1()
'
' Macro1 Macro
' Macro recorded 16-02-2009 by ceng
'

Sheets("Bunker ROB").Select
Sheets("Bunker ROB").Copy
ActiveWorkbook.SaveAs Filename:= _
ActiveWorkbook.Path & Range("D3"), _
FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False

[Code] ........

View 2 Replies View Related

Macro To Transfer All Data From One Workbook To Specific Sheet In Another Workbook

Feb 23, 2014

I have data in 2 different workbooks, and I need to transfer all data in 'Jx_ex1' to sheet1 in the 'template' workbook, and all data in 'Gr_ex1' to sheet2 in 'template' workbook. All data should be transferred to the same cell numbers, from A1 to Y5000. I actually have loads of workbooks to transfer to the template but if I have an example with the two then im sure I can work out how to modify it. All files will be in the same folder.

View 8 Replies View Related

Save Single Sheet To New Workbook And Delete VBA Code From New Workbook

Jun 25, 2014

I'm trying to find a way to save a single sheet of an excel workbook and in the same process delete all vba code and shapes from the new single sheet workbook. I was looking around and found this code which does save only the single sheet to a new one sheet workbook but doesn't delete the vba and shape that I have used to assign macros to in the original.

Code:
Sub SaveSheetAsNewBook()
Dim wb As Workbook
Dim InitFileName As String
Dim fileSaveName As String
Dim wshape As Shape
InitFileName = ThisWorkbook.Path & Format(Date, "mm.dd.yy")

[code]....

View 2 Replies View Related

Open Workbook, Find Sheet That Contains Cell Value From Active Workbook

Jun 20, 2008

I'm trying to figure out a way to find a specific sheet in a workbook that does not contain the macro. Within the macro I have a cell which holds the name of the specific sheet I would like to find but I can't get it to work for some reason...

'Dim officen As Integer
'Dim thiswb As Workbook

officen = Range("A2").Value
Set thiswb = ActiveWorkbook
' Open the Active Info file
Workbooks.Open "C:My DcoumentsActive 20080616.xls", , , , "xxxxxx"
' Dim sourcewb As Workbook
Set sourcewb = Workbooks.Open"Active 20080616.xls"

Sheets("officen").Select
RowCount = ActiveSheet.UsedRange.Rows.Count
Range("B2").Select.............................

View 8 Replies View Related

Making / Defining Workbook As Variable In VBA Macro?

May 7, 2014

In my VBA macro, it copies data from this.workbook, and paste to another "destination" workbook. That destination workbook must be opened first before the macro is run.

Within the Macro code, I had to specify the exact name of the workbook which the data is pasted to.

The problem is that the exact name of that workbook which it paste to changes every week.

Is there any method where my macro can be changed and updated with the name of the destination workbook each week without manually opening and editing the code. The user of this.workbook is not technical enough to edit and maintain the macro each week

View 8 Replies View Related

SUMPRODUCT To SUM Variable Range In Closed Workbook

Feb 12, 2010

I have a closed workbook with data in 12 columns. I have an other workbook where I choose a column and the formula needs to return the sum of the data from column 1 to the chosen column, in a given row. I can't use INDIRECT or SUMIF because of the closed workbook, so I'll probably need a formula using sumproduct, but I can't find a solution on the net.

View 2 Replies View Related

Selecting Range Variable In Different Worksheets Within Same Workbook

Aug 22, 2014

I want to make a range variable ("testrange") that I can use to define a range of non-continuous cells and then use that range variable to select that range of cells in different worksheets within the same workbook.

I tried the below code (simply coloring cells red), but get an error when I try to select "testrange" after moving to the next worksheet.

[Code] .....

The next worksheet is also supposed to have the same range of cells colored red, but I can only get it to work on the first active sheet.

I would like to avoid having to repeatedly rebuild the range I want selected each time I move to a different worksheet.

View 7 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved