Consulting

Results 1 to 5 of 5

Thread: Solved: using name in VBA propertys vs Sheet name

  1. #1
    VBAX Regular
    Joined
    Oct 2004
    Posts
    65
    Location

    Solved: using name in VBA propertys vs Sheet name

    Hi

    I have this code that Will get Range J5 for the first sheet in the WB the issue I have is people are changing the order of the sheets WB and the names of the tabs (although the data I need will always be in J5 on the sheet)

    Is there any way to change this to look at the sheet named (Sheet1) in the VBA propertys (that will not change) and take cell j5 form that

    I rememberer some one showed me that once but I can't rememberer how for the life of me


    [VBA]Sub WBLoop()

    Dim wbk, ThisWorkBook As Workbook
    Dim row As Integer

    row = 1
    Set ThisWorkBook = ActiveWorkbook

    For Each wbk In Workbooks
    If wbk.Name <> ThisWorkBook.Name Then
    wbk.Sheets(1).Range("j5").Copy
    ThisWorkBook.Sheets(1).Range("A" & row).Select
    '' ThisWorkBook.Sheets(1).PasteSpecial xlPaseValues
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
    [/VBA]
    We are living in a world today
    where lemonade is made from
    artificial flavoring and furniture polish
    is made from real lemons...
    Alfred E Newman

  2. #2
    Moderator VBAX Master geekgirlau's Avatar
    Joined
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    1,464
    Location
    If you have the VBE Properties window displayed, you can give the sheet a name. Then you can use the following type of reference:

    [VBA]
    shData.Range("j5").Copy
    [/VBA]

    We are what we repeatedly do. Excellence, therefore, is not an act but a habit.
    Aristotle

  3. #3
    VBAX Regular
    Joined
    Oct 2004
    Posts
    65
    Location
    Quote Originally Posted by geekgirlau
    If you have the VBE Properties window displayed, you can give the sheet a name. Then you can use the following type of reference:

    [VBA]
    shData.Range("j5").Copy
    [/VBA]

    So would [VBA]shData[/VBA] be the name in the VBE Properties?
    We are living in a world today
    where lemonade is made from
    artificial flavoring and furniture polish
    is made from real lemons...
    Alfred E Newman

  4. #4
    Moderator VBAX Master geekgirlau's Avatar
    Joined
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    1,464
    Location
    Yes. In the Project Explorer, click on the sheet you want to name. Then in the Properties window, change Name to whatever you like.

    Generally I would suggest that you name all of your sheets in this way - it makes it a lot easier to reference them, and ensures that they are never impacted by a change in sheet order or tab name.

    We are what we repeatedly do. Excellence, therefore, is not an act but a habit.
    Aristotle

  5. #5
    VBAX Regular
    Joined
    Oct 2004
    Posts
    65
    Location
    thanks I got it to work
    We are living in a world today
    where lemonade is made from
    artificial flavoring and furniture polish
    is made from real lemons...
    Alfred E Newman

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •