Consulting

Results 1 to 4 of 4

Thread: About referring to cells

  1. #1
    VBAX Regular
    Joined
    Oct 2008
    Posts
    31
    Location

    About referring to cells

    I have understood that
    [VBA]cells(x,y)[/VBA]
    and
    [VBA]activesheet.cells(x,y)[/VBA]
    means the same.

    If I want to refer to thisworkbook.activesheet.cells(x,y), is there a shorter way to do it? Is it possible to make cells always refer to thisworkbook.activesheet.cells?

    Thanks!

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    With ThisWorkbook.Activesheet

    .Cells(x,y)
    .etc

    End With
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Regular
    Joined
    Oct 2008
    Posts
    31
    Location
    Ok. That seems to work. Thanks!

  4. #4
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    You can also create a variable for the sheet, and use that throughout your code.
    [vba]
    Dim ws As Worksheet
    Set ws = ThisWorkbook.ActiveSheet
    ws.Cells(x, y).etc.

    [/vba]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

Posting Permissions

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