Excel 2002 (10.2) - Using the LEFT function in a macro

Paddington1881

Board Regular
Joined
Jan 12, 2005
Messages
62
Office Version
  1. 2016
Platform
  1. Windows
Hi all

I've been tinkering with ways to include the LEFT function in a macro, but without success.

I'm trying to isolate the first 2 characters in an a cell, and then use that to go to a separate worksheet with the same 2 character name. For instance:

Cell A1 is "AD1234". I want the macro to recognise the "AD" part and go to a worksheet called "AD" and do some stuff (lookups etc).

I thought it would be quite easy but I'm absolutely stumped. I'm going through Excel VBA For Dummies now, but I get the feeling I'm a level below dummy cos I'm just not getting it. Is what I'm trying to do possible?

Any pointers much appreciated, as always.

Thanks
Darren
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Code:
Sub test()
Dim MyName As String
MyName = Left(Sheets("Sheet3").Range("A1").Value, 2)
Sheets(MyName).Select
End Sub

BUT you do not need to select this sheet to work with it.
 
Upvote 0
VOG II - you are a star. That works great.

lasw10 - thanks for your reply but I couldn't get your code to work for me.

Best regards to you both

Darren
 
Upvote 0

Forum statistics

Threads
1,214,932
Messages
6,122,323
Members
449,077
Latest member
jmsotelo

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