ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Copy Problem (https://www.excelbanter.com/excel-programming/354205-copy-problem.html)

Syed Haider Ali[_32_]

Copy Problem
 

Dear Friends,

I have the following codes to copy specific data from one sheet to
another

Private Sub CommandButton1_Click()
Dim x As Long
Dim y As Long
y = 1
For x = 1 To 65536
If Cells(x, 1).Value =1245 And Cells(x, 1).Value <= 2000 Then
Cells(x, 1).EntireRow.Copy
Sheets("sheet2").Cells(y, 1).PasteSpecial
y = y + 1
End If
Next x
Application.CutCopyMode = False
End Sub

1. Col A of active sheet has numeric values which are copied from
1245 to 2000 in Sheet2. If Col A contains Date values then above codes
does not work. How can I overcome the problem ?

2. If I create a temp worksheet through userform and then copy from
one sheet to tempws then these codes does not work.

The code for creating temp worksheet are as

Private sub userform_activate()

Dim tempws as worksheet
Set tempws = Thisworkbook.worksheets.add
Tempws.name = “Temp”

End sub

How I can overcome the above two problems

Thanks

Syed Haider Ali


--
Syed Haider Ali
------------------------------------------------------------------------
Syed Haider Ali's Profile: http://www.excelforum.com/member.php...o&userid=21994
View this thread: http://www.excelforum.com/showthread...hreadid=515923


Jim F

Copy Problem
 
#1 sounds like a data type issue...try checking to see if the value of the
referenced cell in numeric before checking to see if it fits the criteria of
the copy loop...i.e:

Private Sub CommandButton1_Click()
Dim x As Long
Dim y As Long
y = 1
For x = 1 To 65536
If isNumeric(Cells(x,1).Value) = true then
If Cells(x, 1).Value =1245 And Cells(x, 1).Value <= 2000 Then
Cells(x, 1).EntireRow.Copy
Sheets("sheet2").Cells(y, 1).PasteSpecial
y = y + 1
End If
End If
Next x
Application.CutCopyMode = False
End Sub


"Syed Haider Ali" wrote:


Dear Friends,

I have the following codes to copy specific data from one sheet to
another

Private Sub CommandButton1_Click()
Dim x As Long
Dim y As Long
y = 1
For x = 1 To 65536
If Cells(x, 1).Value =1245 And Cells(x, 1).Value <= 2000 Then
Cells(x, 1).EntireRow.Copy
Sheets("sheet2").Cells(y, 1).PasteSpecial
y = y + 1
End If
Next x
Application.CutCopyMode = False
End Sub

1. Col A of active sheet has numeric values which are copied from
1245 to 2000 in Sheet2. If Col A contains Date values then above codes
does not work. How can I overcome the problem ?

2. If I create a temp worksheet through userform and then copy from
one sheet to tempws then these codes does not work.

The code for creating temp worksheet are as

Private sub userform_activate()

Dim tempws as worksheet
Set tempws = Thisworkbook.worksheets.add
Tempws.name = €śTemp€ť

End sub

How I can overcome the above two problems

Thanks

Syed Haider Ali


--
Syed Haider Ali
------------------------------------------------------------------------
Syed Haider Ali's Profile: http://www.excelforum.com/member.php...o&userid=21994
View this thread: http://www.excelforum.com/showthread...hreadid=515923




All times are GMT +1. The time now is 08:51 PM.

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