?
Solved

Explicitly reference a sheet

Posted on 2013-12-03
5
Medium Priority
?
189 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 52

Accepted Solution

by:
Rgonzo1971 earned 2000 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.

770 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