using =right() and =left() in VBA

lhernandez

Active Member
Joined
May 22, 2006
Messages
282
I know this is very simple question and I have done this before I can just not remeber.
I have a cell the reads either ##C or ##TR.
I am trying to write an if statment stating
if the right value of sheet1 cells(x,y) = "C" then
etc.
else
if the right of sheet1.cells(x,y) = "TR" then
etcs...
end if
Can someone please help me! :)
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Well I don't think either Left or Right are what you are looking for if there is always 2 characters/digits before what you want to test.
Code:
Select Case Mid(Cells(x,y),3)
       Case "C"
            ' do something
        Case "TR"
            ' do something else
        Case Else
            ' do something completely different
End Select
 
Upvote 0
Hi,

surely when you type "left" or "right" in the VBA-helpfiles, you would get your answer
try this
Code:
If Right(Cells(1, 1), 1) = "C" Then MsgBox "hello"
kind regards,
Erik

EDIT: adjust last argument when you need two characters
Code:
If Right(Cells(1, 1), 2) = "CC" Then MsgBox "hello"
 
Upvote 0

Forum statistics

Threads
1,214,911
Messages
6,122,192
Members
449,072
Latest member
DW Draft

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