Solved

Explicitly reference a sheet

Posted on 2013-12-03
5
174 Views
Last Modified: 2013-12-03
Hi,

Im going back and forward to a worksheet with a very long name, so am trying to call it something short to make my code a bit shorter and neater

The below is not working for me, can someone explain how i can just call my activesheet "LOB" and then refer to that when im going back and forth

Thanks

....................................



Sub CopyFormats()

Dim SheetName As String
SheetName = "LOB"





    Range("G4:G32").Select
    Selection.Copy
    Sheets("RBWM").Select
    Range("H4").Select
     Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
        False, Transpose:=False
   Sheets("LOB").Select
0
Comment
Question by:Seamus2626
  • 2
  • 2
5 Comments
 
LVL 50

Accepted Solution

by:
Rgonzo1971 earned 500 total points
ID: 39692193
Hi
pls try

Set LOB_Worksheet = Sheets("the long name of the Sheet")
' instead of Sheets("LOB").Select 
' use
LOB_Worksheet.Select

Open in new window

Regards
0
 

Author Closing Comment

by:Seamus2626
ID: 39692196
Perfect, thanks
0
 
LVL 4

Expert Comment

by:yuppydu
ID: 39692465
I know it is closed but why don't you just rename the sheet in the VBA property window?  It's much simpler and you do not need any code. Moreover if at one point you want to change the sheet tab name this will not affect your code
0
 

Author Comment

by:Seamus2626
ID: 39693099
Thanks for the update yuppydu!
0
 
LVL 4

Expert Comment

by:yuppydu
ID: 39693142
My pleasure Seamus, if it is not clear how to do that write me a line... and BTW try to avoid the .Select command, there are very few occasions where it is necessary
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Excel if statement 3 15
A Table within a User Form 24 42
Index Match Array? 5 34
COPYING ROW W/ CHECKBOX TO SEPARATE SHEET 3 19
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question