Macro to enter data based upon portion of sheet name

JPM

Active Member
Joined
Aug 1, 2002
Messages
406
I am trying to write code that would enter data into a cell based upon how the name of the worksheet ends.
E.g.:
If Worksheet name end with 123 then enter "ABC" into A1, otherwise enter "XYZ"

I have been trying to do this simple thing in all different kinds of ways, but so far no luck.
Can anyone please help me in my misery?
Thanks.
JPM
 

Some videos you may like

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.

Tom Urtis

MrExcel MVP
Joined
Feb 10, 2002
Messages
11,208
This might help.

Sub Test1()
With Range("A1")
If Right(ActiveSheet.Name, 3) = "123" Then
.Value = "ABC"
Else
.Value = "XYZ"
End If
End With
End Sub
 

JPM

Active Member
Joined
Aug 1, 2002
Messages
406
THANKS!

I knew it was something simple, I just had a brain freeze.
Thanks a bunch. This was really holding me up.
JPM
 

Watch MrExcel Video

Forum statistics

Threads
1,114,096
Messages
5,545,926
Members
410,713
Latest member
TaremyLunsil
Top