Passing Variables

Rocky0201

Active Member
Joined
Aug 20, 2009
Messages
278
Please let me know how I can pass a variable from my double click code to my user form code.

Here's what I have done and it does not work...

In Sheet1--

Public TestTarget As Integer
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Dim FileToOpen As String
Dim RtnCd As Integer, ResetCd As Integer
Dim ContinueFlag As Integer
Dim LastFile As String
Dim LastDate As Date
Dim Filterby As Integer
'----------------------------------------------
' Total Incidents Selected
'----------------------------------------------
Select Case Target.Column
Case Is = 1
Select Case Target.Row
Case Is = 2
TestTarget = 1
Application.ScreenUpdating = False
UserForm2.Show
End Select
End Select
End Sub

In UserForm2 --

Public TestTarget As Integer
'OK Button Pressed
Private Sub CommandButton1_Click()
Application.ScreenUpdating = False
If SortColumn = "" Then
SortColumn = "B1"
Exit Sub
End If
Call ResetCurrentReport("Report", ResetCd)
Call CreateCurrentReport("Report")
ResetCd = 1
Call ResetCurrentReport("Report", ResetCd)
Call BuildSortReport("Report")
LR = Sheets("Report").Cells(Rows.Count, 1).End(xlUp).Row
If SortDirection = 1 Then
Range("A1:H" & LR).CurrentRegion.Sort Key1:=Range(SortColumn), Order1:=xlDescending, Header:=xlYes
Else
Range("A1:H" & LR).CurrentRegion.Sort Key1:=Range(SortColumn), Order1:=xlAscending, Header:=xlYes
End If
Unload Me
Call UnBuildSortReport("Report")
Call FormatReport("Report")
SortColumn = ""
Sheets("Report").Activate
Application.Goto Range("A1"), True
Sheets("Summary").Activate
Cells(1, 1).Select
Application.ScreenUpdating = True
End Sub
Private Sub UserForm_Initialize()
End Sub

Once I know how to pass a variable to userform2, I will then write code to support the variable being passed.

Thanks.
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Never mind... I figured it out... Althogth I had the variable TestTarget defined as Public in Module 4 (all by itself), I was inadvertenly restting the variable by doing a Dim in the UserForm2 and Double Click.

Once I removed those statemnts, it seems to work fine now...
 
Upvote 0

Forum statistics

Threads
1,214,932
Messages
6,122,332
Members
449,077
Latest member
jmsotelo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top