left or right in tab

mrinal saha

Board Regular
Joined
Jan 20, 2009
Messages
229
Hi Folks,

I have a sheet with name as below: I want to set a condition if the sheet name is RCD (Non-Recallable). How to identify in vba what is the right part of the tab name.

05252011 RCD (Non-Recallable)

Thanxxxx,
Mrinal
 
Well I am so sorry for the incomplete info...

Here it is :

L = loop for number of sheets
i = loop for Sheets("Rough"), column 1 that contains all the sheet names. And the error msg i am getting is Subscript out of range

For l = 1 To Sheets.Count
For i = 3 To Sheets("Rough").UsedRange.Rows.Count
If Sheets(l).Name = Sheets("Rough").Cells(i, 1).Value And Split(Sheets(l).Name, " ", 2)(1) = "Sale" Or _
Split(Sheets(l).Name, " ", 2)(1) = "RCD (Non-Recallable)" _
Or Split(Sheets(l).Name, " ", 2)(1) = "PDR(Non Recallable)" Then
deal = Sheets("Rough").Cells(i, 4).Value

Hope this make sense..
thanks,
Mrinal
 
Upvote 0

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
From memory, Split will return that error if the current string doesn't contain the specified delimiter. i.e. if there is no single space in Sheets(l).Name

Maybe testing the name with Instr would be a safer option.
 
Upvote 0
Code:
[COLOR="Blue"]Function[/COLOR] IsRCD(Sh [COLOR="Blue"]As[/COLOR] Worksheet) [COLOR="Blue"]As[/COLOR] [COLOR="Blue"]Boolean[/COLOR]
    Application.Volatile
    [COLOR="Blue"]With[/COLOR] CreateObject("VBScript.RegExp")
        .Pattern = "RCD (Non-Recallable)"
        [COLOR="Blue"]If[/COLOR] .Test(Sh.Name) [COLOR="Blue"]Then[/COLOR] IsRCD = [COLOR="Blue"]True[/COLOR]
    [COLOR="Blue"]End[/COLOR] [COLOR="Blue"]With[/COLOR]
[COLOR="Blue"]End[/COLOR] [COLOR="Blue"]Function[/COLOR]
 
Upvote 0
From memory, Split will return that error if the current string doesn't contain the specified delimiter. i.e. if there is no single space in Sheets(l).Name.
Ahh, yes, that may be the problem. I got the impression from Mrinal that all of the sheets she would be testing had a "date" followed by a space followed by more text. There are ways around that problem using Split, but the InStr approach would be more direct in this case.
 
Upvote 0

Forum statistics

Threads
1,225,149
Messages
6,183,193
Members
453,151
Latest member
Lizamaison

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