Pass Variables Between UserForm & Macro

Sep 2, 2007

I am looking at using forms, as in the Userform... Not used them before, but would like to know, if you create a text box on it, is the value global, so any module can use the var? or how can I, so that value entered can be used on the whole book ?

View 3 Replies


ADVERTISEMENT

Pass Variables From Userform To Public Procedures

Nov 17, 2007

When working in an userform, and you call another sub routine within the userform, will all variables passed automatically be byref (no way to do byval?)?

View 3 Replies View Related

Pass And Return Variables?

Mar 21, 2012

Today's question concerns one sub calling another, having the called sub do some stuff that then effects what the calling sub does.

Essentially

Code:
public sub sub1

dim x as integer
dim countCall as boolean

x = activesheet.cells(1,1).value
countCall = False

call sub2(x, countCall)

[code]....

Obviously the above is a very simplified version of what I'm trying to do, since everything there could of course be handled in a single sub. It is for illustration purposes only. My actual main sub needs to call the secondary sub repeatedly in some stacked loops and its in-feasible to but the second sub's code into the main thread.

The problem remains though, I know how to call a sub and pass variables to it, i just have no inkling on how to pass results back to the calling sub. I've tried a few things I've found around the web but I seem to be missing something important.

View 1 Replies View Related

Pass Variables Between Userforms

Jan 26, 2007

I have a userform with a button that wil run macro "sub1". If "sub1" encounters an error on a worksheet it wil show a custom
error messagebox(a userform) that contains the option "Don't ask me again". If true it sets a global variable. Do I need to use global variables to pass to the original procedure "sub1" for the ok/cancel buttons too or is there an other method?

View 3 Replies View Related

Link Variables & Sheets In Macro To A Userform

Jul 24, 2007

I have a sheet with 3 macros. It consists of two macros to produce results, and the third to bridge the two together where is all starts. I have built a userform in the sheet and am trying to get the variables in both sheets, to be user changeable and selectable via the userform.

In the attached data, the userform allows for the selection of two sheets, A and B. The user would select in A the sheet with data which is equivalent to Oval_An and in B the sheet with the data equivalent to Oval_DMA. The first macro, Find_75 runs, followed by the second macro, kTest, all working to produce results when hitting the Subtract button on the form. The Find_75 tolerance are also defined via the useform box, as well as kTest's compare tolerance.

View 6 Replies View Related

Reset Variables For Each Pass Through For Loop

Jun 27, 2014

I am having trouble defining a variable in a For loop. When I run the loop the first time everything seems to work fine, but when the loop goes back through the second time it carries its previous value with it. Here in lies the problem if the variable is supposed to be empty (not assigned a value). So, for example: 'Variable' in the code below may or may not be given a value depending on the conditions in the For i loop. If it is given a value then 'Variable' will still have that value on the next pass through the For j loop. And if none of the conditions are met for the If statement in the For i loop the second time through the For j loop, it should be an empty variable, but instead the code is reading it as having a value (from the previous pass through the For j loop).

[Code] .....

I have tried using:

[Code] .....

After the For j line, and instead of using:

[Code] ....

I tried using:

[Code] ....

and I've tried:

[Code] .....

I get an Object error with either line I use. I just want to be able to reset the variables each time through the For j loop so in the case of an empty variable, it doesn't try to calculate based on the previous value.

View 6 Replies View Related

Pass Array Variables Between Modules

Jun 8, 2007

I am trying to pass a public variable to another module in the same workbook. On Module1 I declare at the top

Public stores
Sub Main()
Dim stores(1 To 100, 1 To 10, 1 To 10)

Reader

...which then calls the procedure Reader in Module2

Sub Reader()
let x=1
let y=1
let z=1
let stores (x,y,z)=activecell.value

I've left out the portions of code that seem irrelevant. When the macro runs, I get a type mismatch error on the "let stores" line. If I move the code from Reader into the procedure Main, it works, so it seems to be an issue with passing the variable. I haven't used multiple modules very often so this is probably a very basic issue.

View 3 Replies View Related

Pass Count By Condition To Variables

Jan 22, 2008

Here in the code wbResults is a Workbook present in my present folder. In the Sheet1 and Column "I", the result of test cases is entered. The Result of the TEST CASES can be PASS or FAIL. So i am trying to get the total number of PASS test cases and Total FAILED test cases. BUT with the code i have written, i am not able to fetch the right data. Is the method of comparing wrong? or what else? i have tried to debug but nothing comes out.

Do While Not i = 1008
If (wbResults.Worksheets("Sheet1"). Cells(i, 8) = "PASS") Then
PASS = PASS + 1
End If
i = i +1
Loop

View 4 Replies View Related

Linking Macros & Pass Values/Variables

Oct 18, 2006

I have a worksheet which I've set to read-only, I am trying to get it to pull in information from external worksheets. I've created a Macro that will automatically bring in the data however it will only go into a pre-defined cell/row. I have another Macro which looks up the next available row (which is where I want the data to go) but can't get it to link into the macro's. In short, Macro1 brings in data, Macro2 finds next available row, Macro3 brings in another worksheet, Macro4 finds next available row etc etc.

Sub Macro3()
With ActiveSheet.QueryTables.Add(Connection:= Array( _
"OLEDB;Provider=Microsoft.Jet.OLEDB.4.0;Password="""";User ID=Admin;Data Source=C:Documents and SettingsjspencerDesktopExcelAMMH.xl" _
, _
"s;Mode=Share Deny Write;Extended Properties=""HDR=NO;"";Jet OLEDB:System database="""";Jet OLEDB:Registry Path="""";Jet OLEDB:Database" _
, _
" Password="""";Jet OLEDB:Engine Type=35;Jet OLEDB:Database Locking................

View 2 Replies View Related

Pass Variable From One Userform To Another?

Oct 20, 2005

I have code in a userform that shows another userform with a text box. When the user types text there and presses OK, I want that userform to close (which it does fine), and return back to the original userform (which it does fine), but I want the typed text to be stored in a variable that the code in the original userform can use.

I tried declaring a public variable, "Rresponse1", in each userform's procedure, but that doesn't work. I test for the content of the variable afterward in the original userform and it is empty.

In the original userform I have:

SaveList.Show '(this is the second userform)
MsgBox "This is response1: " & Response1 '(to test if the variable is being passed)

In the userform SaveList, in the Private Sub CommandButton1_Click() procedure, I have:

Response1 = SaveList.ListName.Text
Application.ScreenUpdating = True
MsgBox Response1 '(to test the variable, here it shows the text fine)
Unload SaveList

How do I get the Response1 variable to keep its content when control is passed back to the original userform?

View 6 Replies View Related

Can't Pass Variable Value From Worksheet Sub To Userform Sub

May 24, 2014

I am trying to pass two variables RARD and CARD from Sheet1 'change selection' subroutine to the 'Set ARD Command button click' subroutine. The variable value remain empty and it gives me a 1004 error when I try to execute this line of code:

[Code] ....

What I am trying to do is put the text value 'ARD' in the cell on sheet1 which was the original cell I clicked on to open the userform2. To do this I click on the 'Set ARD' button on the userform2 which is then suppose to hide the userform2 and put the 'ARD' text in the selected cell on Sheet1.

I have attached the workbook for review : Therapy Tracker - Tester V2.10 - deleted logo.xlsm‎

View 1 Replies View Related

Pass Data From Userform To Worksheet?

Dec 29, 2013

I have two userforms (for simplicity we'll call them UserForm1 and UserForm2). When pulling up data on UserForm1 and selecting CommandButton1 is Unloads the current form and passes the ComboBox1 on the form to a public variable called lSection_Choice. When CommandButton1 on UserForm2 is selected, it uses the public variable lSection_Choice to determine the ListObject on a worksheet and then locate the last row in the first column of the listobject and input the value of the TextBox1 on UserForm2. It runs through without any errors but the worksheets do not update? I am guessing it's because the modal UserForm2 is set and not focused on the worksheet.

Here is the code to pass the public variable

Code:
Private Sub AddTeam_Click()
lSection_Choice = Me.ComboBox1.Value
Unload Me

[Code]....

View 7 Replies View Related

Pass Userform To Public Sub Procedure

Feb 15, 2010

I have a userform that has a number of cascading comboboxes, however i wish to use the same cascading feature in a number of other userforms. So what i am trying to achive is calling the cascading element from a public macro, to do this i need to pass the userform name to the procedure. The snippet of code i am using is:

Form:
Private Sub ComboBox1_Change()
If ComboBox1.Value <> "" Then
myform = Me.Name
Call Cascade1(myform)
End If
End Sub

Module:
ub Cascade1(myform)
myform.Label2.Visible = True
myform.ComboBox2.Visible = True
myform.ComboBox2.RowSource = Range(myform.ComboBox1.RowSource).Cells(myform. ComboBox1.ListIndex + 1, 1)
End Sub

View 2 Replies View Related

Pass Variable To UserForm Module

Dec 28, 2006

I have a macro that when it runs presents a form that gives the user an option to skip the calculations or continue. If they click Skip then it continues the 'Next CE' . My problem is I can't get the Boolean value to pass from the form to the macro. Here is what I have

The main macro

Sub Dividend_MF()
For Each sh In ActiveWorkbook.Worksheets( Array("G&I", "Growth"))
For Each ce In sh. Range("a5:a" & sh.Range("a65536").End(xlUp).Row)
If Not IsEmpty(ce) And Not (IsError(ce.Offset(0, 56))) Then
If ce.Offset(0, 56) = "X" Then

View 9 Replies View Related

VBA Status Of Pass / Fail Required On Userform

May 7, 2014

Per the attached, I have a set of questions which must be answered by true or false. the answer to all is true. I need a pass/fail indicator on the userform to give a user realtime view based on percentage of true answers. threshold can be assumed as 80% where below it is reflected as fail

Capture_Excel Forum Query.JPG

View 6 Replies View Related

Pass UserForm Control Values To Sub Procedures

Apr 19, 2008

I have been trying to use a multi-select listbox as the argument for a subroutine. For some reason, I keep getting a run time error, type mismatch. I'm baffled because when I define the specific listbox, it works fine, but when I attempt to pass the listbox I get an error.

Public Sub OtherDirectTotal(Expense As ComboBox, CostCat As ComboBox, _
Cost As TextBox, Years As Msforms.listbox)
Dim IDC As Double
Dim IDCt As Double
IDC = Val(UserForm2.txtIDC) / 100
If Years.Selected(0) = True Then
If Expense = "Sponsored" Then
If UserForm2.ChkODC = False Then
Select Case CostCat......................

View 2 Replies View Related

Pass String Variable To Userform Using Property Procedures

May 29, 2013

I want to display a string to users. Normally I would do that using message boxes. But that would not give me enough control over the font size, and I want to display using font size 48.

I could have used global variables, but that is not a good coding way. The other way of doing that is using property procedures. I could pass a string variable to a Label control on the form and then could format it.

View 9 Replies View Related

Pass Array Elements To Private UserForm Module

Mar 28, 2008

I am trying to pass a string array into a form. I have added a member string array to the form, and a property to "Let" the array in the the member array.

Private sFormString() As String

Property Let FormString(value() As String)
sFormString = value
End Property

I can pass a string in using a procedure:

Sub StringArrayTest1()

Dim TestString() As String
Dim frmString As FString

but I cannot "modulate" the code, or else I get an internal error (error 51). I.e. this code doesn't work:


Sub StringArrayTest2Mod(TestString() As String, frmString As FString)

frmString.FormString = TestString

End Sub

Sub StringArrayTest2()

Dim TestString() As String
Dim frmString As FString

Set frmString = New FString
Redim TestString(1 To 2)
TestString(1) = "Cat"
TestString(2) = "Dog"

Call StringArrayTest2Mod(TestString, frmString)

End Sub

Does anyone know why this happens? Obviously, in the example code its not an issue, but the application I'm using this for is more complex, and some modulation here would be good.

View 9 Replies View Related

Pass Data From Userform To Excel Sheet Using File Path?

Jan 18, 2012

How to pass data from userform to excel sheet using file path?

View 4 Replies View Related

Pass Calendar Control Date To Selected TextBox On Another UserForm

May 9, 2008

I have a workbook that has multiple spreadsheets. Data is added to the spreadsheets using userforms for each spreadsheet. I have created a pop-up calendar to add dates and want to know if there is a way to add dates without having to create multiple calendars for each txt field on each userform. I would like it so that when I click on the calendar it would put the date into the text field it was launched from.

This is the code in the calendar which only puts the date into the field named Dat_Clsd.

Private Sub CMD_Close_Click() .....

View 5 Replies View Related

UserForm Variables Available To All UserForm Procedures

Jan 16, 2008

I have a userform that should return a global varable but when the global varable is used back in the program...it is 0 and not the number in the userform.

The varable I speak of is ForcedCurrent
Global declairation

Private Type TempData
LotNumber() As String
Site() As String
Macro() As String
ChainName() As String
ResistancePerContact() As Double
Index As Integer
End Type

Private Type Lot
Product As String
ParaOrDeft As String
ThermalOrStress As String
Hours() As String
Data() As TempData
Index As Integer
End Type

Dim LotData As Lot

Dim TestNameArray() As String
Dim NumberOfContacts() As Double
Dim ReedholmUnits() As String
Dim ForcedCurrent As Double ...

View 4 Replies View Related

Excel 2010 :: Pass Date From Datepicker In Userform To A Cell In Sheet

Jul 30, 2012

I am using Excel 2010. I have a user form with a date picker on it. I simply want to transfer the date chosen to cell A3 on a sheet. I have two problems. When I click the date picker, it doesn't show all the days of the month. When I do pick a date, it isn't transferred to the sheet. This is the code I am using in the user form:

VB:
Private Sub DTPicker1_CallbackKeyDown(ByVal KeyCode As Integer, ByVal Shift As Integer, ByVal CallbackField As String, CallbackDate As Date)
meetdate = UserForm2.DTPicker1.Value
Sheets("MeetData").Range("A3").Value = meetdate
End Sub

View 5 Replies View Related

Passing Variables From A Userform

Dec 21, 2009

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?

Example:

View 3 Replies View Related

Using Goal Seek On Userform With Variables

Apr 6, 2013

Goal seek function

Code:
Worksheets("Sheet1").Range("Polynomial").GoalSeek _
Goal:=15, _ ChangingCell:=Worksheets("Sheet1").Range("X")

Is it possible to modify this such that I can use variables? For example, the variables are 'left term', 'right term' and 'sigma max' .

I want to set the value of the following equation 'left term - right term' to 0 by changing variable 'sigma max' Everything is done on the userform and not in the spreadsheet.

(Note: In spreadsheet format, the above query is equivalent to setting a cell which has a formula to 0 by changing the value in another cell, fairly simple).

View 3 Replies View Related

UserForm Variables In Public Modules

Jan 13, 2008

I make a userform called Option and now i want to call some of the variables of the userform in a module. First i try to copy this variables in a cell with the next

ActiveSheet.Cells(2, 3) = Me.MediaP.Value

and it works. But now, i want to call to MediaP in a module. For do that I try to do this:

With Worksheets("Hoja2")
.Range("B1").Value = Option.MediaP.Value

but it doesn't work. I don't want to use public variables or copy/use the information of the cell(2,3), i only want to know how use the information on the textbox called MediaP in a module.

View 3 Replies View Related

VBA Userform - Labeling Depending On Multiple Variables

May 20, 2014

I have the following issue:

I have a table of data, and would like my userform to select parts on this depending on different variables.

When I run the macro "Show_UserFormCalculatePrice" or click the button "Calculate Price", the userform is activated which has 2 comboboxes, Date and Service.

When a certain date a service are selected I would like the the dish name to show in the labels of the userform.

My main issue is that there will be multiple dishes that will correspond to the data, and I would like them to be vertically listed in the labels depending on their number (Column A).

Essentially I would like to run some sort of If function:

If the date and the service correspond to the criteria then they are shown in the labels.

VBALabeling.xlsm

View 3 Replies View Related

Pass Value To Macro In Another Worksheet

Aug 15, 2007

I have one worksheet with a macro which calls a macro in another worksheet. I would like to pass a variable from the first worksheet to the second worksheet.

Worksheet1 macro includes the following line of code to call Macro3 in worksheet2:
Application.Run "'Worksheet2'!Macro3"

Worksheet2 has the following code in Macro3:
Do While response 1 And response 2
response = InputBox("Would you like to print your report on one page or two pages?", "Select number of pages", 1)

[rest of code]

I would like to be able to pass a value of '1' to Macro3 and bypass the message box when Macro3 is called from Worksheet1. However, if the user has Worksheet2 open, macro3 should display the message box.

View 9 Replies View Related

Macro Sub Pass Parameter

Aug 21, 2008

I've written a function to delete the charts on a worksheet: ....

View 9 Replies View Related

Pass Formula To Variable In Macro?

Mar 15, 2012

is it possible to assign the formula to a variable ? here i am trying to get only the filename excluding the path and assign it to a string variable. but its not working check "strr1" line.

Sub TestReadDataFromWorkbook()
' fills data from a closed workbook in at the active cell
Dim tArray As Variant, r As Long, c As Long
Dim i As Integer

[Code]....

View 5 Replies View Related

Macro That Deletes Sheet With Control & Shows UserForm Causes UserForm To Disappear

Jun 15, 2009

This is weird - if you delete a sheet that contained a control then

a. showing a modeless userform resluts in a userofrm that goes invisible at subroutine End
b. public variables lose their value

These things do not happen if the sheet did not contain a control. Attached is an example file - put the inputfile.xls in your default file location (or add a path in the code) then open the ProblemDemo.xls and run the main macro to see it fal - isthis another Excelbug I've found?

View 9 Replies View Related







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