Assign 2 Macros To 1 Button (or Adding VBA Code To The Existing Macro)
Dec 23, 2009
I'm verrry new to editing VBA code and I've been trying to figure out how to send a column of data ("Min Data" AB3:AB21 from "Sheet1") to a worksheet ("F4" - Min) and sending another column of data ("Max Data" AC3:AC21 from "Sheet1") to a different worksheet ("F4" - Max) by using only the one button ("Record Data" from "Sheet1"
I've been trying to figure out ways to edit the VBA in "Module 1" to make this work
Can anyone help me out here? If what i'm asking for isn't clear enough, just let me know and i'll try to explain in more detail.
This works fine, my only problem is if the button that is created is actually named Button2 or 3, etc. Is there a way to assign the new button to a variable, or would it be an object? this way it wouldn't matter what it was named.
My macro essentially requires a deletion of the entire sheet, so I cannot run it through a button, it'd by definition be deleted. So I was thinking to run this macro through the keyboard, how to assign a keyboard key to existing macro?
Private Sub Worksheet_Change(ByVal Target As Range) For Each Cell In Target If Cell.Column = 4 and Cell.row >= 17 and Cell.row <= 20 Then If Cell <>"" Then Cell.Offset(0, 3) = Date Else Cell.Offset(0, 3) = "" End If End If Next Cell End Sub
I wish to assign that code to a button on sheet 1.
I normally just right click the buitton and assign the macro, but on this occasion I can't. I think it's to do with it being a private sub.
While practicing writing macros and studying the VBA code, I decided to add a button to run the macro, something I've done many times in the past. But the option to associate the new button with any macro doesn't seem to be available.
I would like to add a pause to the following macro so that it inserts the word CANCEL 1 second after triggering. I know I need to use the Application.Ontime function but cannot work out how to integrate it.
Code: Sub Cancel() Application.ScreenUpdating = False Sheets("Sheet1").Range("T5") = "CANCEL" Application.ScreenUpdating = True End Sub
I have to modify 2000 files so I've written a master file that loops through a list, importing modules and forms into the 2000 files it opens and closes. On each file when open it draws a button on worksheet. I then want to assign a macro to the button called "ModifyMenu" . The code for 'Modifymenu' is imported into file_01.xls and is a unique name. It does not exist is master.xls, so no confusion.
The code for assigning the code is as follows :
Windows("file_01.xls").Activate ActiveSheet.Shapes("Button").Select or Workbooks("file_01.xls").Sheets("1 B").Shapes("Button").Select
Then
Selection.OnAction = "ModifyMenu" (This links to master.xls!ModifyMenu not file_01.xls)
Selection.OnAction = "file_01.xls!ModifyMenu" (This fails, runtime 1004. 'Unable to set the OnAction property of the button class)
Selection.OnAction = ThisWorkbook.Name & "!ModifyMenu" (This links to master. MAster is the active code even though 'file_01.xls' is the active worksheet)
Variations on the above seem to result in the same 1004 error or linking back to master regardless of the fact I'm trying to link to file_01.xls.
I have a start page in the beginning of my excel workbook. This is where i want to assign a macro to a search button. I want the macro to search the entire workbook but only in a certain block on each worksheet.
Created a button in a spreadsheet but cannot activate the shortcut menu that contains "assign macro." Help says select the button, right click on a handle and a shortcut menu appears with "assign macro." Not. I right clicked every handle numerous times and get the regular shortcut menu without the "assign macro" option.
I'm trying to assign a shortcut to a macro I wrote in VB. However, when I go to Tools->Macros->Macros, none of my macros (whether coded in VB or recorded) have the "Options..." button enabled, so I can't assign the macro. This happens whether I use Excel 2003 or Excel 2007. The file is not readonly and I have tried the various levels of macro security. I have VBA installed.
Is there a VBA code that will enable me to create a button and assign a certain macro to it everytime I insert a new worksheet?
how to insert a new worksheet with VBA, what I want is that when I insert that worksheet, there is already a button there with a specific macro(already made) assigned to it.
See attached file illustrating exactly what I'm trying to do.
I won't repeat the exact same things I wrote in the file, but the Summary is that I need to first make such that only certain check boxes can checked at any one time, then make the command button run certain macro(s) depending on which boxes are checked.
I have created a individual tracker spread sheet in each user system and on the spread sheet I have inserted 2 buttons in 1st sheet. when employee wants to take a break he has to click on the log out button and when he came back he needs to click on login button. I have another sheet named "timings" and I have created 2 columns, one is login and another is logout. What I need is when user click on the login button, the system time and date to be auto update under login column and when he clicks on logout button the system time and date to be auto update under logout column.
I have a macro which I use to do all sorts of routine things on a spreadsheet for my employees. (you guys helped me with that too. thanks)
I would like to add a command button to this sheet to run series of code and I want to add this to the final step of a macro.
Question, is there a series of code, which would 1. create the command button on the active sheet, and 2. add the required code to the command button, and 3. embed that button and code onto the active sheet all at once.
?
I need to do this regularly so it is a currently manual process I am trying to replace.
Ex. of code I want placed:
Rows("1:1").Select Selection.Font.Bold = True
This is not the exact code which I will use, but it will help me to understand what I would have to do to make it work.
I have been using this code and just noticed that it resets all of my options buttons to false when I exit and then re-enter (activate) the sheet with the option buttons.
I see where this is going on, but don't know how to correct it. I only want the option buttons changed to false if
The Sol named range is something other than "Primary Vendor". It seems to call the macro ClearOB whenener the sheet is activated.
Private Sub Worksheet_Activate() If Range("Sol").Value = "Primary Vendor" Then For Each OB In ActiveSheet.OptionButtons OB.Enabled = True Next OB ClearOB ActiveSheet.ScrollArea = "A1:K58"
I have managed to create something similar to what i am working for using an example from Lacher and Gant Charts. i am now stuck as I can enter more than 40 status as it then gives me an error. The following is the code: Can any1 highlight where i need to make any changes to stop the error from occuring:
Option Explicit Sub CreateTimeChartData() Dim vTimeData As Variant Dim i As Integer Dim sRoom As String Dim vLastEndTime As Variant Dim oSeries As Series ' set up Application. ScreenUpdating = False Application.DisplayAlerts = False ' create chart data worksheet With Worksheets("TimeData"). Range("TimeList"). CurrentRegion .Sort Key1:="Room", Key2:="Start Time", Header:=xlYes vTimeData = .Value Worksheets.Add On Error Resume Next Worksheets("ChartData").Delete..........................
I written VBA code to create a new sheet and embed a command button on it. I want to assign a macro to this button but when I click on the button the assign macro button is greyed out. I have plenty of macros saved and the VBA code has finished running so why should this be?
Attached is my sample data Sample Data_Combine Sheets.xlsm.
What the code in the attached sheet does is that it combines the data in Sheets Set1 and Set2 into the worksheet named "Combine".
Both input sheets share same columns. Code I use is as below:
VB: Sub BuildPivotData() Dim wrsht As Variant Dim i As Integer
Sheets("Combine").Range("A2:AI500").Clear wrsht = [{"Set1", "Set2"}] For i = 1 To UBound(wrsht) Sheets(wrsht(i)).[a2].CurrentRegion.Offset(1).Copy Sheets("Combine").Range("A65536").End(xlUp)(2) Next i End Sub
I want to amend the output in such a way that when the macro is run , in the "Combine" worksheet an additional column is added at the start(col A) with header as "Category".
The category should be nothing but the input Sheet name i.e Set1 or Set2.
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.
CASH BK CASHIERS DATE CASH TOTAL DIFF SALES GBP AR GBP AR GBP
[code]....
above is the sheet template we use on a monthly basis. I would to like to use a command button which will run a macro creating a new sheet with the sheet name each month. The idea is to have a text box and a command button,enter the month in the text box and click the button. A sheet for the month to create at end.
I have my main directory C:Perinatal Within that directory I have folders that contain results for each medical conditions (see attachments)
Within each subdirectory are 6 workbooks with (untidy) data results, all the same format just different numbers for each analysis. I want my MAIN_MACRO to loop through every single .xls file in the C:Perinatal, cleaning up the data of all files, and then saving.
I can use the following code to cycle through each folder one at a time, however, I'd like to loop through every subdirectory of
C:Perinatal instead to speed up the process, rather than having to change the path for each subfolder (e.g. C:PerinatalCANCERALL). Is this possible?
If this isn't possible how can I create a 'MyPaths' list and loop through all those directories.
I've added the following code into macro i have assigned to the button on this attached worksheet which deletes any row where the cell in the A column is blank.
I currently have an excel workbook (2010) in which I created a custom ribbon and assigned several different macros to the buttons.
Long story short, I will be saving several variations of this workbook every so often when I get new data.
The problem is that if I change the name of the file (Save as or Rename), the custom ribbon buttons no longer work. When I assigned the macros to the ribbon buttons, the macros were absolutely assigned.
Is it possible to assign relative macros to custom ribbons?
From research I have done, it appears that custom ribbons cannot be created using VBA. Is this still true?
VBA COde for adding CC, BCC to email sent from excel. I already have the below code to send email from worksheet, i need to add a copy email.
Private Declare Function ShellExecute Lib "shell32.dll" _ Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, _ ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, _ ByVal nShowCmd As Long) As Long
Im trying to autimatically insert a RTD formula in a cell but it is failing trowing the error 1004 : 'runtime 1004: application-defined or object-defined error'