Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1
Default data selection and copying

I'm new at this so I'm not sure of the validity of my question. I'm
trying to import data from a standardized format. The problem is that
the number of rows will vary depending on the set of data. So I need
some code that will take a selection starting from "Operating
Expenses" to the last expense (always 2 cells above "Total Operating
Expenses"). This is what I've got so far:

Sub CommandButton1_Click()
Sheets("Cash Flow").Select
ActiveSheet.Range("A1").Select
Do
ActiveCell.Offset(1, 0).Select
Loop Until ActiveCell.Offset(1, 0).Value = "Operating Expenses"
Set TopCell = Cells(ActiveCell.Row, ActiveCell.Column)
Do
ActiveCell.Offset(1, 0).Select
Loop Until ActiveCell.Offset(1, 0).Value = "Total Operating Expenses"
ActiveCell.Offset(-1, 0).Select
Set BottomCell = Cells(ActiveCell.Row, ActiveCell.Column)

Range(TopCell, BottomCell).Select
Selection.Copy
Sheets("Sheet1").Select
Selection.Paste
End Sub

I keep getting the "selection method of range class failed" error for
the "Range(TopCell, BottomCell).Select"

Any suggestions?

Thanks!

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 4,339
Default data selection and copying

try:
Sub CommandButton1_Click()

Dim topcell As Range
Dim bottomcell As Range

Sheets("Cash Flow").Select
Set Cell = Range("a1")
Do
Set Cell = Cell.Offset(1, 0)
Loop Until Cell.Value = "Operating Expenses"

Set topcell = Cells(Cell.Row, Cell.Column)

Do
Set Cell = Cell.Offset(1, 0)
Loop Until Cell.Value = "Total Operating Expenses"

Cell.Offset(-2, 0).Select

Set bottomcell = Cells(ActiveCell.Row, ActiveCell.Column)

Range(topcell, bottomcell).Copy Sheets("Sheet1").Range("a1")


End Sub

" wrote:

I'm new at this so I'm not sure of the validity of my question. I'm
trying to import data from a standardized format. The problem is that
the number of rows will vary depending on the set of data. So I need
some code that will take a selection starting from "Operating
Expenses" to the last expense (always 2 cells above "Total Operating
Expenses"). This is what I've got so far:

Sub CommandButton1_Click()
Sheets("Cash Flow").Select
ActiveSheet.Range("A1").Select
Do
ActiveCell.Offset(1, 0).Select
Loop Until ActiveCell.Offset(1, 0).Value = "Operating Expenses"
Set TopCell = Cells(ActiveCell.Row, ActiveCell.Column)
Do
ActiveCell.Offset(1, 0).Select
Loop Until ActiveCell.Offset(1, 0).Value = "Total Operating Expenses"
ActiveCell.Offset(-1, 0).Select
Set BottomCell = Cells(ActiveCell.Row, ActiveCell.Column)

Range(TopCell, BottomCell).Select
Selection.Copy
Sheets("Sheet1").Select
Selection.Paste
End Sub

I keep getting the "selection method of range class failed" error for
the "Range(TopCell, BottomCell).Select"

Any suggestions?

Thanks!


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
data selection Desmond Excel Discussion (Misc queries) 1 March 2nd 07 03:36 AM
Copying Excel 2003 Selection into Outlook 2003 HTML E-Mail Message [email protected] Excel Discussion (Misc queries) 0 July 10th 06 03:07 PM
Moving a Selection of data??? Lime Excel Worksheet Functions 3 December 17th 05 06:55 PM
Getting error "selection is too large" when copying data Tootie Excel Discussion (Misc queries) 1 October 6th 05 12:19 AM
Getting error "selection is too large" when copying data Tootie Excel Discussion (Misc queries) 0 October 5th 05 08:42 PM


All times are GMT +1. The time now is 05:56 PM.

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"