+ Reply to Thread
Results 1 to 2 of 2

VBA Ctrl + A Problem

  1. #1
    Registered User
    Join Date
    07-26-2010
    Location
    US
    MS-Off Ver
    Excel 2003
    Posts
    23

    VBA Ctrl + A Problem

    Hi all,

    I’m trying to incorporate code into my macro that selects all filled cells. After searching through the forums, I saw that

    Sheets("Sheet1").Select
    activecell.CurrentRegion.Select

    can be used to select all of the filled cells in a sheet. This code works in the macro for the first sheet of the Excel document (“Sheet1”), but when I try to use it in the same macro for another sheet in the document with the code

    Sheets("Sheet2").Select
    ActiveCell.CurrentRegion.Select

    the macro selects the same range of cells that was selected on the first sheet. Why won’t it select the new range of filled cells in Sheet2 instead of selecting the same range from Sheet1? I can’t figure out why it merely selects the same range from Sheet1..thanks in advance for your comments, ideas, and suggestions.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: VBA Ctrl + A Problem

    The main problem you're having is with ACTIVECELL and SELECTING. Activecell always refers to the currently activesheet, which is poor way to reference values.

    Selecting in general is a bad idea. Why are you selecting? What is the NEXT thing you are going to do?

    Once you move into VBA, you can stop interacting with your sheet like a human does (select, type, confirm)...instead you can send commands directly into properly denoted targets.

    Please Login or Register  to view this content.
    ...etc.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1