Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Copying Range

Hi All:

I am trying to create code that when a command button is pressed, it will
open a workbook, copy the data and close the workbook. Then paste the data
in the current workbook and fill a combobox. I am receiving an error with
ActiveSheet.Range(Cells(1, 1), Cells(numRows, 35)) .Copy .Range ("A1").
What am I doing wrong?


Private Sub CommandButton1_Click()
Dim numRows As Long

Workbooks.Open Filename:="c:\CCF\Contracts1.xls"
With ThisWorkbook.Worksheets("Sheet1")

'*** Determine number of rows ***
numRows = Application.CountA(ActiveSheet.Range("A:A"))

'*** The number of columns will always be a static 35 (i.e. A:AI) **
ActiveSheet.Range(Cells(1, 1), Cells(numRows, 35)) .Copy .Range
("A1")
.ComboBox1.ListFillRange = .cells(1,1),.cells(numrows,35)
.ComboBox1.ListIndex = 0
End With
ActiveWorkbook.Close

End Sub


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,236
Default Copying Range

I see two possible reasons:
1. There's a space before .Copy
2. numRows turns out to be 0


--
Rob van Gelder - http://www.vangelder.co.nz/excel


"PokerDude" wrote in message
news:knjUb.177634$sv6.938184@attbi_s52...
Hi All:

I am trying to create code that when a command button is pressed, it will
open a workbook, copy the data and close the workbook. Then paste the

data
in the current workbook and fill a combobox. I am receiving an error with
ActiveSheet.Range(Cells(1, 1), Cells(numRows, 35)) .Copy .Range ("A1").
What am I doing wrong?


Private Sub CommandButton1_Click()
Dim numRows As Long

Workbooks.Open Filename:="c:\CCF\Contracts1.xls"
With ThisWorkbook.Worksheets("Sheet1")

'*** Determine number of rows ***
numRows = Application.CountA(ActiveSheet.Range("A:A"))

'*** The number of columns will always be a static 35 (i.e. A:AI) **
ActiveSheet.Range(Cells(1, 1), Cells(numRows, 35)) .Copy .Range
("A1")
.ComboBox1.ListFillRange = .cells(1,1),.cells(numrows,35)
.ComboBox1.ListIndex = 0
End With
ActiveWorkbook.Close

End Sub




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
Copying to a range jclandmark Excel Discussion (Misc queries) 0 February 19th 09 03:21 PM
Copying a Range Peter[_8_] Excel Discussion (Misc queries) 1 December 11th 07 04:14 AM
Copying and pasting from a range John Excel Worksheet Functions 3 June 6th 07 05:22 PM
copying a named range jenniebentham Excel Discussion (Misc queries) 0 December 20th 06 04:51 PM
Copying a range to the row below Trevor[_3_] Excel Programming 2 October 20th 03 07:51 PM


All times are GMT +1. The time now is 12:47 AM.

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

About Us

"It's about Microsoft Excel"