VBA Split not working

Charmwah

Board Regular
Joined
Jan 23, 2017
Messages
64
Hi all

No doubt an easy fix to this. I have the following code whereby i'm trying to split a two word string into just the last word. The string originates from a combobox selection:

Code:
Private Sub FamilyCombo_Change()


Dim Coat As String
Dim Coaty As String
    Coat = FamilyCombo
    Coaty = Split(Range(Coat).Value)
    Me.CoatingCombo.List = Range(Coaty).Value


End Sub

The error I get is "run time error 1004 method range of object global failed". The 'Coat' string returns a named range within the worksheet if that has any bearing?

Kind regards
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Is Coat meant to be the name of a named range?

If it is have you checked the named range selected in the combobox?

Also, have you checked it's scope?

Based on that you might need to include a worksheet reference for the range.
 
Upvote 0
I think I see what you're attempting I think.

Norie is of course correct. Also Coaty needs to be declared as an array by using parenthesis:

Code:
Private Sub FamilyCombo_Change()

Dim Coat As String
Dim Coaty[COLOR=#ff0000]()[/COLOR] As String


    Coat = FamilyCombo
    Coaty = Split(Range([COLOR=#ff0000]"[/COLOR]Coat[COLOR=#ff0000]"[/COLOR]).Value)
    Me.CoatingCombo.List = Range(Coaty).Value


End Sub
 
Upvote 0
Hi Norie

The selection returned from the FamilyCombo combobox will be a two word string, but only the last word of the string is the named range.

Thanks
 
Upvote 0
The below doesn't work either since 'coat' is not the named range, nor is the value from the combobox. Its the last word of the two word string that is the named range, thats what I'm trying to extract...

I think I see what you're attempting I think.

Norie is of course correct. Also Coaty needs to be declared as an array by using parenthesis:

Code:
Private Sub FamilyCombo_Change()

Dim Coat As String
Dim Coaty[COLOR=#ff0000]()[/COLOR] As String


    Coat = FamilyCombo
    Coaty = Split(Range([COLOR=#ff0000]"[/COLOR]Coat[COLOR=#ff0000]"[/COLOR]).Value)
    Me.CoatingCombo.List = Range(Coaty).Value


End Sub
 
Upvote 0
How about
Code:
Private Sub FamilyCombo_Change()


Dim Coat As String
Dim Coaty As Variant
    Coat = FamilyCombo
    Coaty = Split(Coat)(1)
    Me.CoatingCombo.List = Range(Coaty).Value


End Sub
 
Upvote 0
Hi Fluff

You've solved it once again, thanks very much =D

How about
Code:
Private Sub FamilyCombo_Change()


Dim Coat As String
Dim Coaty As Variant
    Coat = FamilyCombo
    Coaty = Split(Coat)(1)
    Me.CoatingCombo.List = Range(Coaty).Value


End Sub
 
Upvote 0
Glad we could help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,248
Messages
6,171,021
Members
452,374
Latest member
keccles

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