LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 49
Default Using a button to select cells on different worksheets

I have some problems using a single button to copy cells from one sheet to
another - I get a runtime error 1004: "Select method of Range class failed".

The way I have it set up right now is that I have a button on sheet1 that
takes a String from sheet1 as input, copies Rows2:18 from sheet5, selects the
last row with content on sheet1, and pastes the copied material, then selects
Rows20:36 from sheet 5, selects the last row on sheet2, and pastes the new
copied cells. I've set it up as follows:

Sub Click(): Gets the String input from a cell on sheet1, and then calls
CopyToSheet1(Stringinput) and CopyToSheet2(Stringinput)

In CopyToSheet1(Stringinput) I have it do the following

Find the last row of sheet1:

Dim LastRow As Integer
LastRow = Worksheets("Sheet 1").Cells(ActiveSheet.Rows.Count,
"B").End(xlUp).Row + 2

Then I print the StringInput in a cell on sheet5, copy rows(2:18) from
sheet5, and finally paste my copied material:

Worksheets("Sheet 5").Rows("2:18").Copy
Worksheets("Sheet 1").Cells(LastRow, 1).Select
ActiveSheet.Paste

This works great. It manages to find the right cells on sheet5, and it
manages to find the last row on sheet1, and it pastes perfectly. I would like
to get rid of the extra step, and just have paste it directly rather than
selecting first and pasting to activesheet, but as far as I can tell it's not
possible to simply replace Copy with Paste ("object doesn't support this
property or method").

Anyway, that works fine. For copytosheet2, however, I get "Select method of
Range class failed" when it's trying to select the last row on sheet2. The
debug shows me that it's defined the lastrow properly (in the test case it's
defined as "29" on sheet2, whereas it's "23" on sheet1), but it simply can't
select it. Is this because the button is on sheet1 and the selection I want
is on sheet2? That doesn't seem to stop the .copy command which works fine;
can i get .paste to do this for me?

I tried to be as detailed as possible, and hopefully it was possible to
follow my description and you know how to help me. Thanks!
 
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
I wan to select a button Happy Excel Discussion (Misc queries) 3 September 24th 08 01:19 AM
autofill button is not appearing when I select cells in Excel 2007 plantfood Excel Worksheet Functions 0 September 12th 08 12:23 PM
Creating/Naming New Worksheets Based on Select Cells in Master Worksheet Lilbit Excel Worksheet Functions 2 March 19th 08 05:05 PM
Excel 2003 is missing toolbar button select visible cells select visible cells Excel Worksheet Functions 1 August 15th 06 07:34 PM
select specific cells and consolidate same over many worksheets MikeR-Oz New Users to Excel 2 March 18th 06 01:27 PM


All times are GMT +1. The time now is 12:07 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"