Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 114
Default selecting a cell


Hi,
using excel 2003.

Can you tell me why the following code is not working? Why do I have
to perform this action in two steps?

Not working:
ThisWorkbook.Sheets("Staff Monday").Range("B2").Select

Working:
ThisWorkbook.Sheets("Staff Monday").Select
Range("B2").Select

I have pasted values to a large range in "Staff Monday" and do not
want the range to remain selected once the code has run.

thanks,
Matt
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default selecting a cell

Hi,

In the first snippet of code your trying to select a range on an inactive
worksheet and you can't do that or at least I don't know how.

On the second you make the sheet active so can select a range.

Mike

"MJKelly" wrote:


Hi,
using excel 2003.

Can you tell me why the following code is not working? Why do I have
to perform this action in two steps?

Not working:
ThisWorkbook.Sheets("Staff Monday").Range("B2").Select

Working:
ThisWorkbook.Sheets("Staff Monday").Select
Range("B2").Select

I have pasted values to a large range in "Staff Monday" and do not
want the range to remain selected once the code has run.

thanks,
Matt

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default selecting a cell

Matt,

You cannot change the selection on an inactive sheet.

Note that you do not need to select a range to paste values - this works just as well, with no
selection:

ThisWorkbook.Sheets("Staff Monday").Range("G1:G10").Value =
ThisWorkbook.Sheets("DataBase").Range("B1:B10").Va lue

HTH,
Bernie
MS Excel MVP


"MJKelly" wrote in message
...

Hi,
using excel 2003.

Can you tell me why the following code is not working? Why do I have
to perform this action in two steps?

Not working:
ThisWorkbook.Sheets("Staff Monday").Range("B2").Select

Working:
ThisWorkbook.Sheets("Staff Monday").Select
Range("B2").Select

I have pasted values to a large range in "Staff Monday" and do not
want the range to remain selected once the code has run.

thanks,
Matt



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,480
Default selecting a cell

Hi Matt

You can't select a cell on an inactive sheet. If your Sheets("Staff Monday")
is the active sheet at the time, then the command would work, as would the
more simple
Range("B2").Activate

I suspect you are copying by selecting the range first.
There is no need to do this e.g.

Sheets("Sheet1").Range("A2:A20").Select
Selection.Copy Sheets("Sheet3").Range("A2")
will make the ranges A2:A20 be marked on both sheets and Sheet3 will be the
active sheet at that point

whereas
Sheets("Sheet1").Range("A2:A20").Copy Sheets("Sheet3").Range("A2")
will make the copy and whatever sheet you were on at the time the command
was executed will remain the active sheet.
Only the range A2:A20 will be marked on Sheet3
--
Regards
Roger Govier

"MJKelly" wrote in message
...

Hi,
using excel 2003.

Can you tell me why the following code is not working? Why do I have
to perform this action in two steps?

Not working:
ThisWorkbook.Sheets("Staff Monday").Range("B2").Select

Working:
ThisWorkbook.Sheets("Staff Monday").Select
Range("B2").Select

I have pasted values to a large range in "Staff Monday" and do not
want the range to remain selected once the code has run.

thanks,
Matt


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel 2007 single cell selecting muliple cell Submit2s Excel Worksheet Functions 1 February 12th 09 04:52 PM
Selecting a cell entry based on cell validation selection Brutalius Excel Worksheet Functions 2 December 17th 08 03:44 AM
Transfer cell values to another cell by selecting button. Gryndar Excel Worksheet Functions 2 November 24th 08 02:21 AM
enter text in cell just by selecting cell dlyon Excel Programming 2 December 15th 07 06:37 PM
Selecting 10 charcters on one cell and pasting to another cell [email protected] Excel Programming 10 February 26th 07 07:56 PM


All times are GMT +1. The time now is 09:44 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"