Syntax For Referencing Other Workbooks / Worksheets

Jul 20, 2012

I'm trying to optimize code by avoiding activating other worksheets, but I'm running into a problem with a match function.

I'm using a workbook called "Template" and then opening another workbook called "DCP" and trying to use the match function to figure out what row data is on. I can get this first line of code to work:

HTML Code:
MatchedRowNumber = WorksheetFunction.Match(Combo, Sheets("Sheet1").Range("A:A"), 0)

However for that to work, I have to activate the other workbook. I want to avoid that and stay within the "Template" workbook. I think I need something like this:

HTML Code:
MatchedRowNumber = WorksheetFunction.Match(Combo, DCP.Sheets(DCPSheet).Range("A:A"), 0)

That one however doesn't work... looks like I have the wrong syntax.

Below is an excerpt for the code in case something is wrong with how I set the variables.

HTML Code:
Sub StockOrderByDCP()

Dim Template As Workbook
Dim DCP As Workbook

Dim MSS As Worksheet
Dim DCPSheet As Worksheet

[Code] ..........

View 4 Replies


ADVERTISEMENT

Excel 2007 :: Syntax For Referencing Worksheet In A Formula

Apr 19, 2012

I am using Excel 2007 in Windows XP. I am trying to change the worksheet referenced in a formula from the label of the worksheet to the index of the sheet. I want to use this macro in multiple workbooks, and the relevant sheets have different names but are all in the same position.

I used "record macro" to get the structure of my code. It gave me the line:

ActiveCell.FormulaR1C1 = "=SUM('8Nov11'!R[13]C[-4]:R[108]C[-4])"

I want to change that '8Nov11' to the 3rd worksheet from the left, so something like:

ActiveCell.FormulaR1C1 = "=SUM(ThisWorkbook.Sheets(3)!R[13]C[-4]:R[108]C[-4])"

I can't get this to work, and I can't find the syntax for this anywhere. I've tried with and without quotes, exclamation points, changing to A1 notation and using "Range," "Sheets," "Worksheets," "Item(3)", and many other combinations, but haven't gotten it right.

Most of the errors I get are "Runtime Error 1004: Application-defined or object-defined error."

View 3 Replies View Related

Combobox - Syntax For Worksheets Not Userforms

Nov 24, 2011

I am trying to use code here to facilitate "cascading" comboboxes. However, my comboboxes are in a worksheet, not a userform and I am unsure which bits of the syntax are incorrect.

Currently I am stuck at
" . . . . .
For I = nr + 1 To N
Controls("ComboBox" & I).Clear
. . . . "

The error message tells me that "Sub or Function not defined."

I think (??) the Controls function relates to User Forms, not activex and worksheets, but I don't know what to replace it with or how to alter the syntax.

View 2 Replies View Related

Referencing Workbooks ..

Jul 20, 2008

I have this excellent code which I found on here that looks at the data in column A, looks at the data in column B & then returns the differences ie.

A_____________B_________C___________D______________E
John________Jimi_________________Not in A_______Not in B
Paul________Sporty________________Jimi____________John
George______Ginger________________Eric____________Posh
Ringo_______Scary_________________T-Bone__________Baby
Posh________Eric
Scary_______Ringo
Sporty______Paul
Ginger______George
Baby________T-Bone

Here is the code ....

View 9 Replies View Related

Indirect Formula Syntax For Referring To A Range On Two Worksheets

Jul 5, 2012

B1=Name of WorkSheet
B2=Name of 2nd Worksheet

I am trying to write a sum formula using Indirect so that the end-user can enter the names of the sheets in B1 & B2 (the values are always in cell F5 on each sheet). I thought this would work but it is throwing a REF# error.

=SUM(INDIRECT("'"&B1&":"&B2&"'!F5"))

with some added spaces for clarity:

=SUM(INDIRECT(" ' " & B1 & " : " & B2 & " ' ! F5"))

View 9 Replies View Related

Referencing External Workbooks?

Jun 6, 2014

I'm trying to set-up a costing system as follows:

Each job has it's own xls file, this is a list of manually input costs and a total cost at the bottom (total is the same Cell reference: G24) for all xls files. The xls file is named the same as the job - F0001, F0002 etc.

At the end of every month we then want to create a master list xls file for all jobs being invoiced that month. This is a list of all the jobs - F0001, F0002 etc. In Column A, and the corresponding cost totals in column B.

In the master file we want to be able to type in the job reference to column A (i.e. the file names of the single job files -F0001, F0002 etc) and have the corresponding total for that reference display automatically in Column B (i.e. Cell G24 from file F0001 will display in the master file cell B1, when 'F0001' is typed in cell A1).

Ideally the master file would display all the individual entries automatically, so no need to input the job references either - simply scanning the directory for the other files present and creating a list automatically in the master file, alternatively it can get the job reference from Cell A1 in the individual job files, instead of from the file name.

View 2 Replies View Related

Referencing Images Across Workbooks

Oct 22, 2008

I'm trying to get a system setup with a workbook acting as a reference document, sort of read only and on a separate server. Which is then referenced by another "working" workbook, no problem so far other than I want to be able to view/show images from within the main reference workbook in the destination working workbook. I want this to happen when a user inputs a code, it should populate a series of cells including showing a small jpeg of said item.

For example if I use the camera function it doesn't do as desired when the main reference workbook is not currently open.

I was hoping to avoid macro's or vb if at all possible.

I'm a bit of an Excel novice though have limited programming experience in other languages / applications. I'm also a complete novice when it comes to forums and threads etc. so excuse me if I mess up protocol at all.

View 9 Replies View Related

Referencing Many Closed Workbooks

Nov 3, 2009

I have a workbook for each day recording energy usage from 52 meters,

I need to collate the data on a single workbook.

The only way i can think of doing it is to use the INDIRECT function but this will not work on closed workbook.

I need to sum the contents of B1:AW1 on the closed workbook and input that into a cell on the new sheet.
then repeated for B2:AW2, B3:AW3 up to B52:AW52 once this has been done the process needs to be repeated for 31 workbooks.

The end product should be 31 Columns (one for each day ini the last month) and 52 rown (one for each meter) and the total daily consumption for each meter (sum of column B:AW)

View 6 Replies View Related

Referencing User Selected Workbooks

Aug 5, 2008

I would like the user to select two files, the macro then inputs a formula that includes vlookup to the other sheet. However i am not sure how to reference each workbook.

Sub InsertLocationContents()

Dim rng As Range
Dim LastRow As Long

'OPEN CSV FILE WITH LOCATION CONTENTS

csvFN = Application. GetOpenFilename(Title:="Select Location Contents csv file")
If csvFN = False Then
' They pressed Cancel
MsgBox "Stopping because you did not select a file"
Exit Sub
Else
Workbooks.Open Filename:=csvFN
Workbooks.OpenText Filename:= _
csvFN, Origin:=437 _ .............................

View 9 Replies View Related

3-D Formula Syntax: Consolidate Certains Cells In 30 Identical Worksheets In A Workbook

Jun 7, 2006

I want to consolidate certains cells in 30 identical worksheets in a workbook. I understood that if I use the 3-D formula method, that I could insert new identical worksheets into the range of worksheets and the consolidated totals would update. Is that correct?

I cannot seem to get the syntax to work. When I read the Excel Help file it gives an example of =sum(sheet2:sheet7!B3) but I don't understand how Excel could answer this ( if the worksheets were named Sheet2,sheet3,sheet4 etc up to sheet7)
In my example, the formula is clearly wrong. Why does it not use the single quotation marks '? I cannot find references to the proper syntax anywhere. I have your training program but this does not spell it out for me either. If I use Data>Consolidate then I have to labouriously do this for each cell that I want to consolidate.

View 2 Replies View Related

Copy Worksheets From A Couple Of Workbooks To Other Workbooks

Jun 26, 2014

I have 25 files with certain worksheets that I need to move to 25 other files.

Worksheet 1, 2, 3 and 4 in Workbook A needs to be moved to Workbook A-2014 Worksheet 1, 2, 3 and 4 in Workbook B needs to be moved to Workbook B-2014 Worksheet 1, 2, 3 and 4 in Workbook C needs to be moved to Workbook C-2014 etc....

Is there a way to do this with a macro? Preferably I would like to do this automaticly - i.e. runing the macro from a master file that

1. Opens Workbook A copies the worksheets
2. Open Workbook A-2014 paste the sheets
3. Save and close Workbook A-2014
4. Close workbook A without saving

then doing the same for Workbook B, etc.

View 5 Replies View Related

Copying Formulas Across Workbooks Without File / Book Referencing?

Aug 13, 2012

How to copy a formula (16 columns) from a workbook to another, without referencing the source workbook.

Some people are using tricks such as replacing the equal sign "=" for another character such as "^" then using replace all to put the equal sign back again... but this is too much trouble.

View 2 Replies View Related

Referencing Between Worksheets

Dec 29, 2006

here's a simple discription of what I would like to do:

I have two worksheets open, SHEET1 and SHEET2

In SHEET1 I have numbers 1,2,3...10 running in cells A1.....A10

What I would like to do is add up a certain range of rows in
SHEET1 from target values I place in SHEET2

example:
in SHEET 2:
A1 = 3 ( I insert begining row )
A2 = 5 ( I insert last row )
A3 = equation to add up rows 3 to 5 in SHEET1, ie: A3+A4+A5

What is the equation I should put in A3? This driving me nuts!!

View 9 Replies View Related

Referencing Across Worksheets

Jun 20, 2006

in sheet1 i have a list of names in column B. in the next columns(C to H) i have some numerical data about them. in sheet2 i want to keep only the names and the data in column H. all works fine except... if i insert another line in sheet1 the data in that line is not inserted in sheet2. and if i remove a line in sheet1 i get a ref error in sheet2. what can i do so the new data is inserted correctly?

View 4 Replies View Related

Cross Referencing Between Two Worksheets

Mar 5, 2014

I need to set up a system for recording data into a certain way.

I a currently using this formula =IF(sheet1!A1:A20="H","Y","") and it kind of works.

Basically i want it to fill a cell in sheet2 with a "Y" if ony one cell between A1 and A20 from sheet1 contain a H. At the moment it only works if a few of the cell between A1 and A20 contain "H".

View 1 Replies View Related

Referencing Worksheets In A Loop

May 2, 2006

Trying to write a macro that will reference one cell in about sixteen different worksheets and return the value of each of those cells. Is there an easy way to do this?

ie.

For n = 1 To n = 15

Worksheet(n + 1).Cell("A1")

Return A1


I know this isn't even close to the right code but this should give you an idea of what I'm trying to do.

View 9 Replies View Related

Suppress Open File Prompt When Copying Over Formula Referencing Closed Workbooks?

Dec 13, 2013

I have an Excel file that contains formulas that reference external workbooks on a shared network. Each month, I copy the column of formulas over to the next month's column. Then, to update the file path, I highlight the new column and do a Find-and-Replace, swapping the previous month's name for the current month. This practice works fine. The only thing is ... the "Open File" promptbox appears for each formula where I updated the file path (i.e. and this can be hundreds instances!). I wind-up having to choose the file from the exact same file path. It is an unnecessary, and annoying extra step to take.

View 2 Replies View Related

If Else Syntax: Change Some Outputs Of The Macro Without Changing The Syntax

Jul 19, 2006

I´m writting a macro. It works find until a certain point. When I want to change some outputs of the macro without changing the syntax, it display an error mesage while runing the macro. It says Else without If. Which is quite disturbing because the Else was not creating any problem before. Here is my macro before I changed the conditions (this one work nicely)

Sub Copy_Sheet_Beta()
Set wba = ActiveWorkbook
On Error Resume Next
If IsWorkbookOpened("Projekt.xls", "C:Documents and SettingsfrederikSkrivebordRedd Barna") Then
Workbooks("Projekt.xls").Activate 'In case open, just activate "Projekt"
Else
Workbooks.Open Filename:="C:Documents and SettingsfrederikSkrivebordRedd Barnaprojekt.xls"
End If
Set wb = Workbooks("Projekt.xls")
wb.Activate
If Not SheetExists(wba.ActiveSheet. Range("C1").Value) Then
MsgBox "overall doesn't exist!"
Else........................................

View 2 Replies View Related

Worksheets & Cell Referencing #REF! Error

Mar 18, 2009

I have 3 worksheets:

Lets call them RED, BLUE AND GREEN

Essentially GREEN pulls Values from BLUE and BLUE pulls Values from RED. Red being the base worksheet from which everything is calculated.

In my GREEN workbook I have the following =MIN('BLUE'!H14,'BLUE'!L14)

And this will work fine.....Until I press a clear Worksheet button that has been implemented on the RED worksheet (button was not implemented by me and I do not wish to edit anything with respect to that button)

When RED is reset the #REF! Error will appear in GREEN. This is fine because it cant find any values From BLUE. However when I do input new values into RED, which in turn updates BLUE which is where GREEN in theory should then be able to pull the results from.... But it just stays with a REF! error.

Is there anyway i can permanently set a CELL to have the following code =MIN('BLUE'!H14,'BLUE'!L14), no matter what happens to other cells?

View 10 Replies View Related

Cross Referencing Names On Different Worksheets

Apr 23, 2009

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 2 Replies View Related

Referencing Cell When Looping Through Worksheets?

Jun 10, 2014

I'm getting an "Invalid or Unqualified Reference" error at the 'division=.cells' line when I try to go through each worksheet and paste some info from there onto a summary sheet. I know there is probably a simple solution that I am oblivious to.

Code:
For Each sheet In ThisWorkbook.Worksheets
i = 1
division = .Cells(2, 1)

[Code].....

View 6 Replies View Related

Dynamically Referencing Worksheets From A Closed Workbook

May 4, 2009

I'm reading data, from specific cells off a closed workbook. When the sheet that needs said cell data is activated, it automatically opens the workbook and references the sheet nessecary. The issue I've come across, is I now need to access another workbook (Easy to open) with 12 sheets 1 for each month, and only read from the worksheet of the actual Month...

Kind of lost on how to possibly make this work. I basically need something like:

=location/[workbook.xls]Month(Today())!cell

View 9 Replies View Related

Macro Referencing Named Range In Worksheets Private Module

Sep 12, 2006

I'm having trouble calling a defined range within a VLOOKUP function in VBA. If the named range is located on the same sheet within which you are running the macro, everything runs fine and all is well in the world.

However, after I relocated the range to a separate sheet (a 'SourceData' sheet to tidy up the user interface sheet), I was getting the following error message:

Method 'Range' of object '_Worksheet' failed

The name is correctly defined - Range("DaysInYear").Select still picks up the correct selection - it's just the VLOOKUP will no longer function correctly.

Here is part of the macro's
For I = 1 To NumberOfDays
Range("A1").Value = DateAdd("d", -(I - 1), EndDate)
If Application.VLookup(Range("A1"), Range("DaysInYear"), 3, False) = 1 Then
If Application.VLookup(Range("A1"), Range("DaysInYear"), 4, False) = 0 Then
ActualNumber = ActualNumber + 1
End If
End If
Next I

View 9 Replies View Related

VBA Code For Worksheets Within Workbooks

Jan 31, 2012

For example, I have 50 clients. In 1 workbook, I have a sheet for each client. When I'm finished with a particular client, I need their one sheet to place in their file and be done with it.

The current process is to open that 1 global workbook, copy and paste the sheet I need into a new workbook and go from there.

I was wondering if there is a simpler way to achieve this with VBA coding?

Ideally, I would like to click an object button and then be prompted to select a worksheet from a list that contains all current non-hidden worksheets.

Once I select a worksheet, I would then be prompted to save as and select a file path. That would save that specific client worksheet in its own file that I selected.

View 7 Replies View Related

Consolidating Several Worksheets From Several Workbooks

Jul 14, 2008

I have several workbooks (around 15) in one folder which all contain the same worksheets but with different data. The worksheets all have the same columns. What I would like is a way to consolidate each of the worksheets of the workbooks into one new workbook by running the code whenever I want it.

In other words I have workbook 1 till 9 which all have worksheet 1 till 3. And I would like to consolidate them into a new workbook with sheet 1 till showing all of the data.

View 9 Replies View Related

Compare Worksheets From Two Workbooks

Dec 21, 2009

I have a master tracking document that I use to record project information. My client sends me an updated schedule each week which may (or may not) have additional stores on it and some of the details of the stores may have changed.

I need a macro to capture these changes from the source spreadsheet (the one the client sends) and update the master tracker. The master tracker has a lot of additional columns of data that I add in myself about each project so I don't want to lose this information. The macro needs to see if the store on the source sheet is already on the master tracker and if it is then it needs to check to see if any of the columns below have changed.

If the store isn't on the master tracker then it needs to be added. There are around 750 stores on the master tracker at the moment so to do it manually takes forever!

Master Spreadsheet

Column A - Retail Region
Column B - Project Name
Column C - Postcode
Column D - Net Selling Area
Column E - Project Manager
Column F - Contractor
Column I - Start On Site
Column J - Launch Date


Source Spreadsheet

Column C - Retail Region
Column D - Project Name
Column I - Postcode
Column J - Net Selling Area
Column M - Project Manager
Column N - Contractor
Column P - Start On Site
Column Q - Launch Date

View 9 Replies View Related

Linking Worksheets In Different Workbooks

Jul 7, 2006

I have three workbooks stored in the same drive(shared drive). Let's call them 1.xls, 2.xls and 3.xls. Each workbook has one sheet.Column A in all sheets is the same. I want to make the following linking:

-Column A of the sheets in 2.xls and 3.xls to be linked and get data from column A of the sheet in 1.xls.
-Column B of 1.xls to be linked and get data from column B of 2.xls and column C of 1.xls to be linked to column B of 3.xls.

So far it sounds easy. What I cannot find is what to do when I insert a row in the sheet in 1.xls and write something in column A. I managed from DATA- IMPORT EXTERNAL DATA to refresh column A of the sheets in 2.xls and 3.xls, so that these columns contain the updated information. I cannot do the vice-versa procedure: for example, to insert something in column B of the sheet in 2.xls and refresh the values of column B of the sheet in 1.xls. The fact is that when I insert a row in 1.xls the right references get lost and move one cell up. I want the references to remain stable. In a way the sheets are interdependent.

View 2 Replies View Related

Activating Worksheets In Different Workbooks

Apr 28, 2007

I have created a macro which unhides a sheet (Email) in one book and takes that info to #1 create an email and #2 open a new file and paste data into it.

Problem is, I want to go back to the first book and hide the sheet (Email) since other users will be using the macro. I keep getting a run time error 9 'Subscript out of range'.

I have my code below. I have commented out the last few lines that used to work before I had to open a new book first.

....

View 9 Replies View Related

Delete Middle (same) Worksheets In Many Workbooks

May 8, 2014

In the attachments is the original format of the workbook, but the sheets are blanco. Did this on purpose, because the info is sensitive.

Is there a method to delete the middle sheets, 'Total1999' and 'Klad1'?

Is there a VBA code do this in a lot of workbooks, the format of all these books are the same.

Plus I'll place them in one map if it's necessary.

View 13 Replies View Related

Save Worksheets As Separate Workbooks

Dec 6, 2009

I have a workbook which have worksheets say A to J. I wanted it to be separated into 10 different workbooks A.xlsx, B.xlsx, C.xlsx and so on in drive C. Could anyone help me here?

View 6 Replies View Related







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