How do I pass values between procedures? I have two command buttons in the worksheet.
If I have a procedure A that asks user to input a value "x", when a command button is pressed.
Then another command button is pressed that passes the value onto another procedure B, which iterates a msgbox as many times as the number x,
How do I pass that value x from one procedure to another?
I am building a tool that uses Pivot Tables (so I can't use track changes) and I have found cool code that will insert timestamp and username in the comment when a change occurs. But I need to modify the code to also take the old value and put it into the comment as well. Here is the code to register the change into the comment:
I think this is a relatively easy issue, but I don't know how to do it. I call the Sub SortRange in another Sub SortDeliver. A range (ran5) is defined in Sub SortRange that I also need to use in Sub SortDeliver. How do I pass the range or get the second sub to recognize the range?
I've a userform (UserForm1) that on closing will open one of 5 other userforms. Which of the userforms that opens will be determined at runtime, depending on an option a user has previously selected. The name of the userform is held in a cell in a workbook and is opened as follows:
I have following code which identifies two worksheets, a source (wbSRC) and a destination (wbDEST). In the following code I am trying to get the values for wbsrc and wbdest to be written to the merged spreadhseet. But I am not sure how to go about this in VBA. The commented out approach does not work.
For Each rcell In wbList.Sheets(1). Range("A1"). CurrentRegion.Columns(1).Cells Set wbDest = Workbooks.Open(rcell.Value) Set wbSrc = Workbooks.Open(rcell(1, 2).Value) wbSrc.Sheets(1).Range(copyAddress).Copy _ Destination:=wbDest.Sheets(1).Range(destAddress) 'wbDest.Sheets(1).Range("q3").Formula = "Workbooks.Open(rcell.Value)" 'wbDest.Sheets(1).Range("q4").Formula = "Workbooks.Open(rcell(1, 2).Value)"
VB: Private Sub Workbook_Open() Call Meetdata End Sub
It calls this macro which is in a standard module:
VB: Public firstvariablename As String Public secondvariablename As String Sub Meetdata() regionname = InputBox("Enter the name of the Region.", "Region Name: North, South, East, West") meetdate = InputBox("Enter the date of the Meet.", "Date of Meet") End Sub
This set-up should make the variables available to all the other macros in the workbook. I have two other macros that need to use the values stored in these two variables that are entered into the two 'InputBox' statements. These two macros are in the same module and follow the 'Meetdata' sub. When I run the first macro, it recognizes the variables. When I run the second macro for some reason the variables are not recognized. To test the values returned by the variables, I placed the following code at the end of the first macro and again at the beginning of the second macro .
At the end of the first macro, the MsgBox returns the correct values stored in the variables which means that when the macro completes its run, the variables still hold their values. When I run the second macro with the MsgBox at the beginning, the Msgbox returns a blank. Somehow, the variables have been re-set to a null value. I can't figure out why the variables have been re-set to null. [URL]
I have created a few User Defined Types in a Main subroutine, but when I pass them into another sub the intelisense for the elements doesn't come up. I can type in the elements manually - and it all seems to work okay - but with a lot of types and elements I really want it to save me the effort.
I think I am confused as to how to declare a variable in one sub and use it as an input into another sub. I have attached some code below that assigns a value to two variables and then calls a sub that uses those values. I am brand new to programming so I guess I am confused how to implement this.
I am trying to eliminate a lot of the global variables from my program by passing the variables to my functions and subs as arguments. I am stuck though when it comes to variables created in userforms.
The program starts with a series of userforms that asks the user for information that will be used throughout the rest of the program. Data is assigned to the variables on the click events. Is it possible, without using global variables, to pass those variables to the rest of the program?
I am using the following code to open a userform. Once the userform is open, the user has the option to choose a continue button or a cancel button. If the user is choosing continue, the code is not working (it always skips to the "else" portion of my "if" statement. I can't figure out why it is doing this.
My code passes a string created by a function to procedure. It all works great, but i need to add something so that if the string = false then sub doesn't run. What's the best way to do that. Here is some of the
It seems to work. Are there any problems with it? Is there a better way?
Code: Function myRangePassExample(RangeA As Range) As Double Dim ArrayA As Variant, ArrayB As Variant Dim iLo As Integer, iHi As Integer, i As Integer Dim jLo As Integer, jHi As Integer, j As Integer Dim Sum As Single ArrayA = RangeA.Value iLo = LBound(ArrayA, 1) iHi = UBound(ArrayA, 1)
I'm trying to figure out how to pass parameters to a date field in a macro to control the display in a pivot table. The macro currently uses a With statement to set the properties of 177 of the 180 dates to false, leaving the remaining three dates true and visible.
I have used my Excel Bible as well as MrExcel.com and tek-tips.com to write the current code I have... but it doesnt work! I think I am just missing a small piece, but I dont see what it is.
I have a macro that calls a userform - from the userform, a Customer is chosen. When the "extract" button is clicked on in the userform, it should pass the customer name to the next macro to do a bunch of stuff - including filtering the data by the customer chosen in the userform.
Here is the code - take a look and see if you can figure out why it doesnt work.
Code for "extract" button (I have tried several differnt variations - this is the current one):
problems with the syntax involved in calling one subroutine from within another. I want to pass two variables calculated in a 'main' sub into the parentheses of another I am calling (see pseudocode below). When I pass one variable, everything works fine, however, when I try to include another, I get an error message - something about expecting an "=" in the syntax, which is clearly not correct.
I have an excel sheet, in that excel sheet is a command button, once clicked the command button creates a Word document.
Im trying to get my VBA script to bold certain text that will be in the word document. But all my attempts to bold certain cell contents have failed. Im not getting any errors from the editor, its just not bolding certain text Ive told it too when the word document gets created.
I have included my script below (And Ive tried the following methods already)
1. ActiveCell.Font.Bold & "This Is Function One, This Text Will Appear Bold" & wks.Cells(ActiveCell.Row, 2) & _
2. "This is Function Two, This Text Will Appear Bold" & wks.Cells(ActiveCell.Row, 2).Font.Bold
3. "This is Function Three, This Text Will Appear Bold" & wks.Cells(ActiveCell.Row, 2) & (ActiveCell.Font.Bold) & _
Sub TransferData() 'This macro transfers the data range to a Word Document ' 'Constants: 'docFullName = The full name of an already existing Word document '
I have an Excel workbook with a command button on it. When this button is clicked I wish to pass the filename of the Excel workbook to my Visual Basic program, I have so far got the following Public 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
I'm trying to set up a journal-type workbook. I have two sheets named Start and End-the first sheet has a cell that contains a formula, =SUM(Start:End!B4) B4 is where you put the number of hours worked in a day. I then run a macro that copies the sheet called Start for each day of the year. What I was expecting was that the cell with the formula would provide a running total of the hours worked through the year on each sheet, but when the sheets are copied the formula changes to =SUM(#REF!B4). My macro to create a copy sheet for the whole year is as follows:
Sub MakeYear() Dim SH As Worksheet Dim D As Date, Y As Long Set SH = ActiveSheet Y = Val(InputBox("Year:")) If Y < 2000 Then Exit Sub If Y > 2100 Then Exit Sub Application.ScreenUpdating = False For D = DateSerial(Y, 1, 1) To DateSerial(Y, 12, 31) Application.StatusBar = D SH.Copy after:=Sheets("Start") ActiveSheet.Range("B2").Value = D ActiveSheet.Name = Format(D, "mmm dd") Next Application.StatusBar = False Application.ScreenUpdating = True End Sub