how to pass a variable no matter what it is

miconian

Well-known Member
Joined
Aug 18, 2004
Messages
769
Hi,

I understand (I think) that you can pass a variable to another routine like this:

Code:
othersub Target:=Range("A5")

But I want to pass the value of Target to another routine, no matter what Target happens to be at the time.

Basically I want to say:

"Okay, another routine is taking over now, and that new routine needs to know the value of Target, whatever it is at this point."

How do you do that?

Thanks...
 
Huh. Problem went away after I quit and restarted Excel. Don't know if it had to do with the fact that I also had changed the secondary procedures to ByVal. Also, I had to exit Excel with task manager; when I tried to do it the normal way, I actually got a msgbox that said "cannot exit Microsoft Excel." Weird.
 
Upvote 0

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Dang, it happened again! Here's the exact error:

Run-time error '-2147417848 (80010108)':

Automation error
The object invoked has disconnected from its clients.
 
Upvote 0
Then I chose "debug," and the code that turned yellow was this:

Code:
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
            xlBetween, Formula1:="apple, orange, pear, banana, mango, peach"

The fruit is just a fill-in here; there were actually many more items. Some of them included apostrophes and question marks. Could that matter?

Addendum: I took out the special characters and I still get the error.

Maybe I have too many "cases" in my "select case"?
 
Upvote 0
My code is like this:

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

If Target.Column = 1 Then
    validlist_Col1 Target
End If ' (If Target.Column = 1 Then)

If Target.Column = 2 Then
    validlist_Col2 Target
End If ' (If Target.Column = 2 Then)

If Target.Column = 3 Then
    validlist_Col3 Target
End If ' (If Target.Column = 3 Then)

End Sub

Private Sub Worksheet_Change(ByVal Target As Range)
Dim x

If Target.Column < 15 Then

    ActiveCell.Offset(0, 1).Select 'move selection one cell to the right

' Show validation list (if there is one) in selected cell
On Error Resume Next
x = ActiveCell.validation.Type
If Err = 0 Then SendKeys "%{down}"
Err.Clear
End If

End Sub

Sub validlist_Col3(ByVal Target As Range)

Select Case Target.Offset(0, -1) 'see what's in column B

    Case "blah"
        ActiveCell.Value = "blorg"

    Case "blech"
        With Selection.validation
            .Delete
            .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
            xlBetween, Formula1:="blah, blah, blah, blah, blah"
            .IgnoreBlank = True
            .InCellDropdown = True
            .InputTitle = ""
            .ErrorTitle = ""
            .InputMessage = ""
            .ErrorMessage = ""
            .ShowInput = True
            .ShowError = True
        End With

Then there are about seven more Cases, all very similar.

End Select

End Sub

I also have Sub validlist_Col2 and Col1, very similar.
 
Upvote 0
Ponsy: I'm reading the stuff you linked to, but most of it is above me at this point. Any further hints would be very much appreciated.
 
Upvote 0
Hi

Try changing the calling routine to the format

validlist_Col1 Range(Target )

Tony
 
Upvote 0
You mean to start the sub with:

Code:
Sub validlist_Col1 Range(Target)
?

VBA won't accept it. The text turns red, and it doesn't even give a horizontal line to show it recognizes the beginning of a new prodedure. Am I misunderstanding?
 
Upvote 0
For what it's worth, the line that lights up yellow after the mysterious error is:

Code:
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
            xlBetween, Formula1:="blah, blah, blah"

...which is part of a Select Case procedure, i.e.

Code:
Case "blah"
        With Selection.validation
            .Delete
            .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
            xlBetween, Formula1:="blah, blah, blah"
 
Upvote 0

Forum statistics

Threads
1,216,156
Messages
6,129,188
Members
449,492
Latest member
steveg127

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