ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   copying a range of cells from one worksheet to another (https://www.excelbanter.com/excel-programming/327650-copying-range-cells-one-worksheet-another.html)

David Gerstman

copying a range of cells from one worksheet to another
 
I've been trying to copy a range of cells based on the time column to another
worksheet. The problem I have is with the
Worksheets(2).Cells(ind,1).select
line. I keep on getting a Runtime 1004 error (Application defined or object
defined error). What is wrong with this code?
Dim date_range As Range
Set date_range = Sheets(1).Range("a2", Range("a2").End(xlDown))

Jim Thomlinson[_3_]

copying a range of cells from one worksheet to another
 
There are a couple of possible problems here...

Worksheets(2) could be hidden. You can not select on a hidden sheet.
ind may not be between 1 and 65,535.

Since you have not posted the code where this line exists it is a little
hard to tell.

HTH

"David Gerstman" wrote:

I've been trying to copy a range of cells based on the time column to another
worksheet. The problem I have is with the
Worksheets(2).Cells(ind,1).select
line. I keep on getting a Runtime 1004 error (Application defined or object
defined error). What is wrong with this code?
Dim date_range As Range
Set date_range = Sheets(1).Range("a2", Range("a2").End(xlDown))
.
.
For Each c In date_range
If c.Value = #6:07:01 PM# Then
Worksheets(2).Cells(ind, 1).Select
Range(select_range, select_range.End(xlToRight)).Select
Selection.Copy Destination:=Sheets(3).Cells(jind, 1)
jind = jind + 1
End If
If c.Value = #6:12:01 PM# Then Exit For
ind = ind + 1
Next c

Thanks,
David


David Gerstman

copying a range of cells from one worksheet to another
 
Worksheets(2) is a worksheet "Sheet2" and it is not hidden.
It ranges from A1:D32000
I hope that helps.
David

"Jim Thomlinson" wrote:

There are a couple of possible problems here...

Worksheets(2) could be hidden. You can not select on a hidden sheet.
ind may not be between 1 and 65,535.

Since you have not posted the code where this line exists it is a little
hard to tell.

HTH

"David Gerstman" wrote:

I've been trying to copy a range of cells based on the time column to another
worksheet. The problem I have is with the
Worksheets(2).Cells(ind,1).select
line. I keep on getting a Runtime 1004 error (Application defined or object
defined error). What is wrong with this code?
Dim date_range As Range
Set date_range = Sheets(1).Range("a2", Range("a2").End(xlDown))
.
.
For Each c In date_range
If c.Value = #6:07:01 PM# Then
Worksheets(2).Cells(ind, 1).Select
Range(select_range, select_range.End(xlToRight)).Select
Selection.Copy Destination:=Sheets(3).Cells(jind, 1)
jind = jind + 1
End If
If c.Value = #6:12:01 PM# Then Exit For
ind = ind + 1
Next c

Thanks,
David


Bob Phillips[_6_]

copying a range of cells from one worksheet to another
 
Initialise jnd to 1

--

HTH

RP
(remove nothere from the email address if mailing direct)


"David Gerstman" wrote in message
...
I've been trying to copy a range of cells based on the time column to

another
worksheet. The problem I have is with the
Worksheets(2).Cells(ind,1).select
line. I keep on getting a Runtime 1004 error (Application defined or

object
defined error). What is wrong with this code?
Dim date_range As Range
Set date_range = Sheets(1).Range("a2", Range("a2").End(xlDown))
.
.
For Each c In date_range
If c.Value = #6:07:01 PM# Then
Worksheets(2).Cells(ind, 1).Select
Range(select_range, select_range.End(xlToRight)).Select
Selection.Copy Destination:=Sheets(3).Cells(jind, 1)
jind = jind + 1
End If
If c.Value = #6:12:01 PM# Then Exit For
ind = ind + 1
Next c

Thanks,
David




David Gerstman

copying a range of cells from one worksheet to another
 
Whoops, I left that out of the code I cut and paste.
It's been done.
David

"Bob Phillips" wrote:

Initialise jnd to 1

--

HTH

RP
(remove nothere from the email address if mailing direct)


"David Gerstman" wrote in message
...
I've been trying to copy a range of cells based on the time column to

another
worksheet. The problem I have is with the
Worksheets(2).Cells(ind,1).select
line. I keep on getting a Runtime 1004 error (Application defined or

object
defined error). What is wrong with this code?
Dim date_range As Range
Set date_range = Sheets(1).Range("a2", Range("a2").End(xlDown))
.
.
For Each c In date_range
If c.Value = #6:07:01 PM# Then
Worksheets(2).Cells(ind, 1).Select
Range(select_range, select_range.End(xlToRight)).Select
Selection.Copy Destination:=Sheets(3).Cells(jind, 1)
jind = jind + 1
End If
If c.Value = #6:12:01 PM# Then Exit For
ind = ind + 1
Next c

Thanks,
David





Don Guillett[_4_]

copying a range of cells from one worksheet to another
 
this seems to work

Sub getvalues()
With Sheet2
ii = 2
For i = 2 To .Range("a2").End(xlDown).Row
If .Cells(i, 1) = #6:05:01 PM# Then
.Range(.Cells(i, 1), .Cells(i, .Cells(i, 1).End(xlToRight).Column)). _
Copy Sheets(3).Cells(ii, 1)
ii = ii + 1
End If
Next i
End With
End Sub

--
Don Guillett
SalesAid Software

"David Gerstman" wrote in message
...
I've been trying to copy a range of cells based on the time column to

another
worksheet. The problem I have is with the
Worksheets(2).Cells(ind,1).select
line. I keep on getting a Runtime 1004 error (Application defined or

object
defined error). What is wrong with this code?
Dim date_range As Range
Set date_range = Sheets(1).Range("a2", Range("a2").End(xlDown))
.
.
For Each c In date_range
If c.Value = #6:07:01 PM# Then
Worksheets(2).Cells(ind, 1).Select
Range(select_range, select_range.End(xlToRight)).Select
Selection.Copy Destination:=Sheets(3).Cells(jind, 1)
jind = jind + 1
End If
If c.Value = #6:12:01 PM# Then Exit For
ind = ind + 1
Next c

Thanks,
David




David Gerstman

copying a range of cells from one worksheet to another
 
Thanks a lot Don. That did the trick.
David

"Don Guillett" wrote:

this seems to work

Sub getvalues()
With Sheet2
ii = 2
For i = 2 To .Range("a2").End(xlDown).Row
If .Cells(i, 1) = #6:05:01 PM# Then
.Range(.Cells(i, 1), .Cells(i, .Cells(i, 1).End(xlToRight).Column)). _
Copy Sheets(3).Cells(ii, 1)
ii = ii + 1
End If
Next i
End With
End Sub

--
Don Guillett
SalesAid Software

"David Gerstman" wrote in message
...
I've been trying to copy a range of cells based on the time column to

another
worksheet. The problem I have is with the
Worksheets(2).Cells(ind,1).select
line. I keep on getting a Runtime 1004 error (Application defined or

object
defined error). What is wrong with this code?
Dim date_range As Range
Set date_range = Sheets(1).Range("a2", Range("a2").End(xlDown))
.
.
For Each c In date_range
If c.Value = #6:07:01 PM# Then
Worksheets(2).Cells(ind, 1).Select
Range(select_range, select_range.End(xlToRight)).Select
Selection.Copy Destination:=Sheets(3).Cells(jind, 1)
jind = jind + 1
End If
If c.Value = #6:12:01 PM# Then Exit For
ind = ind + 1
Next c

Thanks,
David





Don Guillett[_4_]

copying a range of cells from one worksheet to another
 
glad it helped

--
Don Guillett
SalesAid Software

"David Gerstman" wrote in message
...
Thanks a lot Don. That did the trick.
David

"Don Guillett" wrote:

this seems to work

Sub getvalues()
With Sheet2
ii = 2
For i = 2 To .Range("a2").End(xlDown).Row
If .Cells(i, 1) = #6:05:01 PM# Then
.Range(.Cells(i, 1), .Cells(i, .Cells(i, 1).End(xlToRight).Column)). _
Copy Sheets(3).Cells(ii, 1)
ii = ii + 1
End If
Next i
End With
End Sub

--
Don Guillett
SalesAid Software

"David Gerstman" wrote in message
...
I've been trying to copy a range of cells based on the time column to

another
worksheet. The problem I have is with the
Worksheets(2).Cells(ind,1).select
line. I keep on getting a Runtime 1004 error (Application defined or

object
defined error). What is wrong with this code?
Dim date_range As Range
Set date_range = Sheets(1).Range("a2", Range("a2").End(xlDown))
.
.
For Each c In date_range
If c.Value = #6:07:01 PM# Then
Worksheets(2).Cells(ind, 1).Select
Range(select_range, select_range.End(xlToRight)).Select
Selection.Copy Destination:=Sheets(3).Cells(jind, 1)
jind = jind + 1
End If
If c.Value = #6:12:01 PM# Then Exit For
ind = ind + 1
Next c

Thanks,
David








All times are GMT +1. The time now is 03:13 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com