Results 1 to 4 of 4

Thread: VBA - ActiveCell.Select

  1. #1

    Thread Starter
    Member
    Join Date
    May 2011
    Posts
    42

    VBA - ActiveCell.Select

    I'm looking at code written by someone else and trying to make it cleaner/faster/nicer. I'm no expert so it's a good learning experience. One thing I see a few times is

    Code:
    ActiveCell.Select
    Isn't the ActiveCell already selected? So, isn't this command a waste of time? And another time I saw something even worse.

    Code:
    ActiveCell.Offset(0,0).Range("A1").Select
    Isn't this an even more complicated way of saying the same thing, also accomplishing nothing?

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: VBA - ActiveCell.Select

    there is some really cruddy code posted on the internet
    also some really good, i think the above is an example of the bad

    where ever possible you should avoid selecting cells at all, work with fully qualified ranges
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3

    Thread Starter
    Member
    Join Date
    May 2011
    Posts
    42

    Re: VBA - ActiveCell.Select

    My guess is this code came from recording a macro, but I'm not sure. I know that in the process of recording macros, a lot of Select statements appear that are unnecessary.

  4. #4
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: VBA - ActiveCell.Select

    My guess is this code came from recording a macro
    i think you are probably correct
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Tags for this Thread

Posting Permissions

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



Click Here to Expand Forum to Full Width