Refering To Sheet Hosting Macro

Feb 20, 2007

Is there a preferred way of referring to the Workbook or worksheet which is hosting the macro.

For example say I have the following Macro:


Sub test()

Dim MyHostMacroWorksheet As Workbook

'''''''''''''''''''''''''''''''''''''''''''''''''
Set MyHostMacroWorksheet = Workbooks(1)

MsgBox (MyHostMacroWorksheet.Name)
'Works only if macro was inside first workbook opened
'''''''''''''''''''''''''''''''''''''''''''''''''


'''''''''''''''''''''''''''''''''''''''''''''''''
Set MyHostMacroWorksheet = Workbooks("foobar.xls")

MsgBox (MyHostMacroWorksheet.Name)
'Works but have to modify every time I copy code from workbook to workbook
'''''''''''''''''''''''''''''''''''''''''''''''''

End Sub
I am looking for explicitly saying "The Workbook/Worksheet that is specified by VBAProject"

View 9 Replies


ADVERTISEMENT

Refering To A Worksheet With Autoname

Dec 5, 2009

Currently I have a code that names a worksheet automatically with the date the first entry was keyed in. The problem is that I'd like to create a formula that would not be affected whatever the names of these sheets might be. There are 21 sheets, the last sheet would be the one containing the formula adding cell values from the preceeding 20 sheets. I've been scratching my head with this for a while now trying to come up with a workaround solution.

HTML Private Sub Worksheet_Change(ByVal Target As Range)

Dim dateTemp As Date

ActiveSheet.Names.Add Name:="timestamp", RefersTo:=Now()
dateTemp = Val(Mid(ActiveSheet.Names("timestamp"), 2))

'Sheet is given a default name until the first entry.
'The name is changed to the date the entry was made.

If ActiveSheet.Name = "DAY01" Then
ActiveSheet.Name = Format(dateTemp, "MMM dd.hh.ss")

End If
End Sub

View 5 Replies View Related

Sum Row Based On Condition Refering To A Different Row

Dec 9, 2009

I have a problem with bringing up the data I need to cells in one row.

In row 1 I have dates:
23-Nov 24-Nov 25-Nov 26-Nov etc.

In row 2 Quantities:
2000 1500 250 750 etc.

In row 3 I have dates again (I need to start working towards these qty's): 20-Nov 22-Nov 25-Nov 25/Nov. I would like in column A of 4 row to sum all the qty's (row 2) if the date in row 3 is the same or smaller than in row 1 column A. But in column B and forward I want cells to sum qty's if the date in row 3 is the same as the one in row 1. I have tried : =sumproduct((A3:D3<=A1),(A2:D2)) for cell A4

and: =sumproduct((A3:D3=B1),(A2:D2)) for cell B4 and consequently for others. It comes back as zero value even if I see matching dates/qty's. Does anyone know what shall I change in my formula to make it right?

View 3 Replies View Related

Refering Text Box Content In A Formula

May 24, 2007

I have to refer the content of a text box in a formula.
The Text box and the cell containing the formula will be in
the same worksheet.

Is this possible first of all? I searched the excel help in and out
and I could not find a way for this.

View 11 Replies View Related

Public Statement: Refering To Listbox.value

Sep 19, 2008

I have a string variable that I want to make available to all modules. The string variable is a listbox.value. In a Userform I have users select a file from a list of files. This particular selection should then be used in a module of the project. Unfortunately, a Public statement can't be used in a class module to declare a fixed-length string variable. Is there any other way to make this variable available to the module?

View 9 Replies View Related

Refering From Another Workbook By Using The Concatenate Formula

Aug 2, 2006

I would like to reference information from another workbook. Instead of writing the Name of the other workbook I would like to reference through a Concatenate formula (e.g. CONCATENATE("Test"&G2&".xls")). I always get an error message. Is there any way I can reference from another workbook by using the Concatenate or any other formula?

View 5 Replies View Related

Refering To Cell In Closed Workbook

Apr 17, 2007

I'm trying to check if a workbook can be used in some processes later and whithout opening the other workbook. is it possible. i have done this

str_prod_PT = Application. GetOpenFilename
If str_prod_PT <> "FALSE" Then
If Workbooks(str_prod_PT). Sheets(1). Range("A1").Value <> "Ordem" Then
MsgBox "Ficheiro incompativel", vbCritical
Else
TextBox1.Value = str_prod_PT
End If
End If

View 3 Replies View Related

Macro To Copy Current Sheet, Create, & Rename New Sheet From Current Open Sheet

Oct 27, 2008

EXAMPLE: Complete Sheet called "Day1". When day1 is complete you click on button and it then copies itself and creates and renames new sheet to "Day2", then when "Day2" is complete you click on button and it then copies itself and creates and renames new sheet to "Day3", and so on and so forth to "Day30".

View 9 Replies View Related

Macro To Copy Data From Sheet 1 To Multiple Pages On Sheet 2 In Correct Cells

Jan 15, 2009

I have attached a 97-2003 .xls file with data for multiple store locations on sheet 1, and the desired result on sheet 2. I am actually using excel 2007, but I dont think I need any special features that it provides.

I will try to explain the issue here without opening the attachment.

Here is an example of the Data on Sheet1

View 13 Replies View Related

Macro To Copy Sheet From Closed Work Book And Overwrite If Sheet Already Exists

Nov 22, 2009

I am currently using a macro to copy a sheet from a closed workbook in to my current workbook. However this copying is based on the sheet name. At present when I run the following code

View 11 Replies View Related

Excel 2010 :: Macro Runs On Protected Sheet But Changes Protect Sheet Options?

Feb 24, 2011

I am using Excel 2010 and I have a password protected workbook with password protected sheets that uses several macros. Most of them, in order to run, have to un-protect the sheet and then re-protect it again. This has been accomplished easily enough by adding ActiveSheet.Unprotect Password:= "mypassword" and ActiveSheet.Protect Password:= "mypassword" to the appropriate places in the script. All of my macros, which do various things like sorting and moving data, deleting blank rows, displaying dialog boxes containing warning messages etc. run fine.

My problem is this: when I password protect the sheets manually, I have checked the following options in the "Protect Sheet" dialog box. Under "Allow users of this worksheet to" I have checked 1)Select unlocked cells and 2)Format cells. After entering my password and closing the dialog box my sheet is protected, but I can edit cells in the manner my allowances permit. However, once I run any of the macros that un-protect and re-protect the sheet, I remain able to select and edit unlocked cells (practically, for my purposes, this means that I can input data which will appear in the default font size and color of the sheet) but I cannot format cells (which, practically, for my purposes would allow me to occasionally change the font color and size of the data). Naturally, after running a macro, the other cell-formatting options are unavailable to me as well. Is there any way to get my manual selections to remain in place after running a macro that functions as mine do? Or is there any way to make my manual selections the default settings for a protected sheet?

View 4 Replies View Related

Excel 2010 :: How To Assign Macro From One Sheet To Form Button On Different Sheet

Mar 6, 2014

I am running excel 2010 with windows 7. I created a macro in sheet 1 and I wish to activate the macro from sheet 2 using a form button. I have entered the code below. I know how to perform this function on a more simple macro like adding names to cells. This code is a bit more complex I just dont know where to start.

Code:
Sub LoanData()
'
' LoanData Macro

[Code].....

View 3 Replies View Related

Macro That Will Compare The P'folios In Sheet "Data To Sheet Workings

Feb 28, 2009

i need a macro that will compare the p'folios in sheet "Data to Sheet Workings, and then list the p;folios which is in sheet Data but not in workings in Sheet "New", so in the example below this would be ETSTSA ...

View 9 Replies View Related

Macro To Pull Data From Multiple Sheet To Main Sheet Based On Column Headings

Sep 13, 2012

I need a Macro which pulls the data from different sheets of excel (which is not formatted properly) to Main Sheet. Also some of the columns will not have the same names, so macro should handle this exception as well.

View 8 Replies View Related

Make Macro To Bring Tables From Another Sheet To Cover Sheet?

Jul 8, 2014

I am trying to take the tables you will see in the dummy page on the second and third sheet and have them output onto the first sheet based on the parameters of the drop down menus. Is there a way to have a button on the first page that controls a macro to do this?

View 4 Replies View Related

Macro Pull Data From Each Sheet And Create A Summary Sheet

Jan 26, 2009

I need to create a macro that will scan a spreadsheet for the number of sheets and then pull data from the same places on each sheet in order to create a summary sheet. Let me try to explain a little better.

The spreadsheet I'm working with has a separate sheet for each new deal our company makes. Each of these sheets is in the same format - we use a template and fill in the data based on that whenever a new deal emerges. The sheets contain basic info about the deal in the first few rows and columns, then some narratives with dates describing the progress of the deal, and then a list of issues and whether or not they have been resolved. The problem is, each of these sheets contains too much info for a quick, high-level overview with the bosses so they've asked me to create something that will pull the basic info, the most recent narrative, and any unresolved issues from each sheet. This way, each time there's an overview scheduled with the bosses, the macro can be run and it will create a new sheet with data from each sheet in the workbook.

View 9 Replies View Related

Macro Copy Of The Active Sheet And Then Rename The New Copied Sheet

Jul 30, 2009

I'm trying to create a copy of the active sheet and then rename the new copied sheet to what's in cell O4, which is a formula (see below) and then paste value cell O4 in B3 of the copied sheet. However, when I run this macro it doesn't seem to like the second line where I am renaming the sheet (run time error '1004').

"O4" =DATE(YEAR($B$3),MONTH($B$3)+1,DAY($B$3))

Sub NewMonth()

ActiveSheet.Copy Before:=Sheets(Sheets.Count)
ActiveSheet.Name = Range("O4").Value
ActiveSheet.Range("O4").Copy
ActiveSheet.Range("B3").PasteSpecial Paste:=xlPasteValues
End Sub

View 9 Replies View Related

Stop Macro From Changing Onto Sheet Top Sheet And Flickering

Dec 24, 2008

How can I stop my macro from changing onto sheet top sheet and flickering away like mad??

View 2 Replies View Related

Create Macro For Exporting 2 Columns From One Many Sheet To New Sheet

Aug 31, 2013

Create a macro to export 2 column to a new sheet.

I have attached the sample file, check for reference.

I want to export Month and Monthly percentage column to a new sheet..

Efficiency Report Fo TS.xlsx

View 5 Replies View Related

Macro To Unprotect Sheet - Paste Then Protect Sheet

Apr 8, 2014

I want a sheet to copy and paste into another worksheet, I have that code and its working fine, but what I also want to do is for the sheet to be protected,so the code would be, copy, unlock, paste, lock, save.

Here is the code I have so far. I know i have to include ActiveSheet.Unprotect "passowrd" ActiveSheet.Protect "password", but I dont know where to include that last part of the code.

View 5 Replies View Related

Macro To Pull Data From 1 Sheet And Filter Into Another Sheet

May 14, 2014

I'm trying to get the data from Receipt log (sheet 1) to automatically populate into the Print Receipt (sheet 2) and to automatically filter and go to the Activity by account (sheet 3). I am so new to this and totally lost.

See attached sample : Student fees.xlsm

View 12 Replies View Related

Macro To Copy Data From One Sheet - Paste In Another Sheet

Jul 29, 2014

How to create macros. I need to copy a certain group of cells from one sheet to another, and then do it for x number of times. I'm just using the record function and now i'm lost. Here is the code i currently have:

Sheets("Mapping QTR2").Select
Range("B137:D230").Select
Selection.Copy
Sheets("ExpDB_Q1").Select

[Code] ....

Also, column C is blank. i would like to get the values from another list in the same workbook, say "branch list". I would like to populate Column C with one specific branch for each "batch", if that makes any sense...

View 3 Replies View Related

Have Macro Point To Current Sheet Instead Of A Specific Sheet Name

Apr 2, 2009

How do I change this macro to refer to the current sheet name instead of "FullScreen (2)"?

View 4 Replies View Related

Macro To Transfer Data From Sheet 1 To First Available Empty Row On Sheet 2

Jun 25, 2012

I am looking for a Macro which can transfer data from sheet 1 to the first available empty row on sheet 2.

For example, I have data in the following cells on sheet 1: B2, B4, B6, B8, and B10. I want to transfer this data to the first available empty row into cells A1, B1, C1, D1 and E1 of sheet 2. The cell number is ofcourse depending on the first available empty row and could thus be 2, 3, 4, 5 etc.

I also want to delete the data from the original cells in sheet 1 after the data has been transferred.

View 8 Replies View Related

Automatic Macro That Runs From Every Sheet But Only Based On One Sheet

May 13, 2014

I have an automatic macro that runs from every sheet but is only based on one sheet. I had to protect the worksheet and in order to make the macro work I had to add an unlock and a lock code. The problem now is every time a user enters something it looks back to the other sheet and then comes back. Is there a way to prevent the user from seeing this. See code below

Private Sub Worksheet_Calculate()
Sheets("Profit Calc Local Currency").Unprotect Password:="hspricing1"
Application.EnableEvents = False
Dim lr As Long
lr = Cells(Rows.Count, "XEA").End(xlUp).Row
Range("$XEA$1:$XEA$" & lr).AutoFilter Field:=1, Criteria1:="1"
Sheets("Profit Calc Local Currency").Protect Password:="hspricing1"
Application.EnableEvents = True
End Sub

View 5 Replies View Related

Macro For Copying Rows Of Data In Sheet 1 To Sheet 2

Oct 8, 2009

I have a couple of spreadsheets that requires me to copy data from Sheet 1 that matches certain criteria to Sheet 2.

I have tried using posted VB codes that have been written for other people but they dont seem to work (this is probably to do with me not actually knowing what I am doing, as I am not sure what I should be replacing and what I need to be deleting etc out of the pre-written code )

I need to be able to search on column e in Sheet 1 for anything that has just h written in the cell and then copy all the rows that match into Sheet 2. I also would like to ensure that when it is copied it doesnt go in row 2 but maybe 4 or 5 as I have quite allot of headings.

View 9 Replies View Related

Macro To Copy A Number From One Sheet To Other Sheet

Jan 26, 2009

I have a report generated from an application and am looking to format it into a specific format in order to import it into access to be used in a query. Does anyone know how to write a macro which will:-

1. look for a particular word and delete 1 row above it and 16 rows below it, for every time that word appears on the sheet.

2. Look for a specific number (which can be identified by the total number of digits in it and/or the starting series of numbers) from it’s location to another newly inserted column

4.Finally, count the number of rows between the number moved in step 2 and the next similar number and copy the first number in to number of rows = the number of rows between it and the next similar number.

View 9 Replies View Related

Sheet To Sheet Transfer With Macro To Auto Run?

Nov 18, 2011

I am trying to create a transfer of data from one worksheet to another, where Column G is where new data will be entered. I have a macro to sort the data (works great!!), but it is just getting it from one worksheet to another without having formulas in the cells - which can be deleted by my co-workers - to pull the data from one sheet to another.

I do not know if this can be done automatically or not, or if info is updated on one worksheet vs another - if then it will transfer the text.

Example:

(A2)LAST NAME (B2)1ST NAME (C2)RES# (D2)HOUSE (E2)DOB (F2)JOB (G2)SPECIAL
(A3)DOE (B3)JOHN (C3)112233 (D3)1 A2 L (E3)10/10/75 (F3)YES (G3)DR APPT

There are over 300 entries - one row new record. The CommandButton1 works great that I have for compiling and deleting unused rows.

But now I need something to get the data to the blank worksheet to compile data from Column G without formulas in the cells. This was one I found online, tried to adjust it to fit what I need, but I cannot get it to work.

Sub CopyRow(ByRef Target As Range)
Dim DstEnd As Range
Dim DstRng As Range

[Code].....

View 9 Replies View Related

Inserting New Row On Sheet 1 - Macro To Make New Row Appear On Sheet 2?

Jul 24, 2013

In my database I am often inserting a new row in between two rows of data and then entering information across 8 cells. I have to manually enter all of the same information on sheet 2, again between two rows that already have data. Is there a macro or formula that would work so that I don't have to enter it twice?

View 5 Replies View Related

Macro Delete The Sheet And A New Sheet Created

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







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