Solved

Explicitly reference a sheet

Posted on 2013-12-03
5
167 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 49

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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

776 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