Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default Mercy - Need help with Copy/Paste VBA

My reverse engineering skills have finally failed me =(

I need to copy rows based on a set value in Column A, to a different
worksheet and start on the next empty row. I also need to paste special as
the values in the source sheet are generated via formulas.

Sub CopySAP()

RowCount = 2

With Worksheets("SAPUpload").Range("a3:a200")
Set c = .Find("1", LookIn:=xlValues)
If Not c Is Nothing Then
firstAddress = c.Address
Do
c.EntireRow.Copy _
Destination:=Worksheets("SAPUpload2").Rows(RowCoun t)
RowCount = RowCount + 1
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address < firstAddress
End If

End With

End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Mercy - Need help with Copy/Paste VBA

Sub CopySAP()

RowCount = 2

With Worksheets("SAPUpload").Range("a3:a200")
Set c = .Find("1", LookIn:=xlValues)
If Not c Is Nothing Then
firstAddress = c.Address
Do
c.EntireRow.Copy
Worksheets("SAPUpload2").Rows(RowCount).PasteSpeci al _
paste:=xlpastevalues
RowCount = RowCount + 1
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address < firstAddress
End If

End With

End Sub



"AirgasRob" wrote:

My reverse engineering skills have finally failed me =(

I need to copy rows based on a set value in Column A, to a different
worksheet and start on the next empty row. I also need to paste special as
the values in the source sheet are generated via formulas.

Sub CopySAP()

RowCount = 2

With Worksheets("SAPUpload").Range("a3:a200")
Set c = .Find("1", LookIn:=xlValues)
If Not c Is Nothing Then
firstAddress = c.Address
Do
c.EntireRow.Copy _
Destination:=Worksheets("SAPUpload2").Rows(RowCoun t)
RowCount = RowCount + 1
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address < firstAddress
End If

End With

End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Mercy - Need help with Copy/Paste VBA

Just a matter of personal preference but I prefer to do the paste in one
operation

Sub copyit()
Dim MyRange, MyRange1 As Range
Dim Lastrow As Long
For Each c In Sheets("SAPUpload").Range("A3:A200")
If InStr(c.Value, 1) 0 Then
If MyRange1 Is Nothing Then
Set MyRange1 = c.EntireRow
Else
Set MyRange1 = Union(MyRange1, c.EntireRow)
End If
End If
Next
If Not MyRange1 Is Nothing Then
MyRange1.Copy
Lastrow = Sheets("SAPUpload2").Cells(Rows.Count, "H").End(xlUp).Row
Sheets("SAPUpload2").Range("A" & Lastrow).PasteSpecial
End If
End Sub


Mike

"AirgasRob" wrote:

My reverse engineering skills have finally failed me =(

I need to copy rows based on a set value in Column A, to a different
worksheet and start on the next empty row. I also need to paste special as
the values in the source sheet are generated via formulas.

Sub CopySAP()

RowCount = 2

With Worksheets("SAPUpload").Range("a3:a200")
Set c = .Find("1", LookIn:=xlValues)
If Not c Is Nothing Then
firstAddress = c.Address
Do
c.EntireRow.Copy _
Destination:=Worksheets("SAPUpload2").Rows(RowCoun t)
RowCount = RowCount + 1
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address < firstAddress
End If

End With

End Sub

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Mercy - Need help with Copy/Paste VBA

Just a matter of personal preference but I prefer to do the paste in one
operation


And another point compared to your code (as corrected by Joel) my version
runs ~10 times faster without the need to bounce back and forward doing
individual paste operations.

Mike

"Mike H" wrote:

Just a matter of personal preference but I prefer to do the paste in one
operation

Sub copyit()
Dim MyRange, MyRange1 As Range
Dim Lastrow As Long
For Each c In Sheets("SAPUpload").Range("A3:A200")
If InStr(c.Value, 1) 0 Then
If MyRange1 Is Nothing Then
Set MyRange1 = c.EntireRow
Else
Set MyRange1 = Union(MyRange1, c.EntireRow)
End If
End If
Next
If Not MyRange1 Is Nothing Then
MyRange1.Copy
Lastrow = Sheets("SAPUpload2").Cells(Rows.Count, "H").End(xlUp).Row
Sheets("SAPUpload2").Range("A" & Lastrow).PasteSpecial
End If
End Sub


Mike

"AirgasRob" wrote:

My reverse engineering skills have finally failed me =(

I need to copy rows based on a set value in Column A, to a different
worksheet and start on the next empty row. I also need to paste special as
the values in the source sheet are generated via formulas.

Sub CopySAP()

RowCount = 2

With Worksheets("SAPUpload").Range("a3:a200")
Set c = .Find("1", LookIn:=xlValues)
If Not c Is Nothing Then
firstAddress = c.Address
Do
c.EntireRow.Copy _
Destination:=Worksheets("SAPUpload2").Rows(RowCoun t)
RowCount = RowCount + 1
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address < firstAddress
End If

End With

End Sub

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default Mercy - Need help with Copy/Paste VBA

Thanks Joel, as always I learn a little more everytime I come here. The code
works great with one exception. When I run the code a second time it
overwrites what was previously pasted.

"joel" wrote:

Sub CopySAP()

RowCount = 2

With Worksheets("SAPUpload").Range("a3:a200")
Set c = .Find("1", LookIn:=xlValues)
If Not c Is Nothing Then
firstAddress = c.Address
Do
c.EntireRow.Copy
Worksheets("SAPUpload2").Rows(RowCount).PasteSpeci al _
paste:=xlpastevalues
RowCount = RowCount + 1
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address < firstAddress
End If

End With

End Sub



"AirgasRob" wrote:

My reverse engineering skills have finally failed me =(

I need to copy rows based on a set value in Column A, to a different
worksheet and start on the next empty row. I also need to paste special as
the values in the source sheet are generated via formulas.

Sub CopySAP()

RowCount = 2

With Worksheets("SAPUpload").Range("a3:a200")
Set c = .Find("1", LookIn:=xlValues)
If Not c Is Nothing Then
firstAddress = c.Address
Do
c.EntireRow.Copy _
Destination:=Worksheets("SAPUpload2").Rows(RowCoun t)
RowCount = RowCount + 1
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address < firstAddress
End If

End With

End Sub



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default Mercy - Need help with Copy/Paste VBA

Mike thank you very much exactly what I was looking for. I only had to make a
few minor changes to get the exact results I wanted. I will post the modified
code for those that may come after me. I made note of the two changes I had
to make.

Sub copyit()
Dim MyRange, MyRange1 As Range
Dim Lastrow As Long
For Each c In Sheets("SAPUpload").Range("A3:A200")
If InStr(c.Value, 1) 0 Then
If MyRange1 Is Nothing Then
Set MyRange1 = c.EntireRow
Else
Set MyRange1 = Union(MyRange1, c.EntireRow)
End If
End If
Next
If Not MyRange1 Is Nothing Then
MyRange1.Copy
Lastrow = Sheets("SAPUpload2").Cells(Rows.Count, "H").End(xlUp).Offset(1,
0).Row '<--Added .Offset(1, 0)
Sheets("SAPUpload2").Range("A" & Lastrow).PasteSpecial Paste:=xlPasteValues
'<--Added Paste:=xlPasteValues
End If
End Sub

"Mike H" wrote:

Just a matter of personal preference but I prefer to do the paste in one
operation

Sub copyit()
Dim MyRange, MyRange1 As Range
Dim Lastrow As Long
For Each c In Sheets("SAPUpload").Range("A3:A200")
If InStr(c.Value, 1) 0 Then
If MyRange1 Is Nothing Then
Set MyRange1 = c.EntireRow
Else
Set MyRange1 = Union(MyRange1, c.EntireRow)
End If
End If
Next
If Not MyRange1 Is Nothing Then
MyRange1.Copy
Lastrow = Sheets("SAPUpload2").Cells(Rows.Count, "H").End(xlUp).Row
Sheets("SAPUpload2").Range("A" & Lastrow).PasteSpecial
End If
End Sub


Mike

"AirgasRob" wrote:

My reverse engineering skills have finally failed me =(

I need to copy rows based on a set value in Column A, to a different
worksheet and start on the next empty row. I also need to paste special as
the values in the source sheet are generated via formulas.

Sub CopySAP()

RowCount = 2

With Worksheets("SAPUpload").Range("a3:a200")
Set c = .Find("1", LookIn:=xlValues)
If Not c Is Nothing Then
firstAddress = c.Address
Do
c.EntireRow.Copy _
Destination:=Worksheets("SAPUpload2").Rows(RowCoun t)
RowCount = RowCount + 1
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address < firstAddress
End If

End With

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
Automating copy/paste/paste special when row references change Carl LaFong Excel Programming 4 October 8th 07 06:10 AM
which line mercy script nastech Excel Discussion (Misc queries) 6 February 5th 06 04:46 PM
help w/ generic copy & paste/paste special routine DavidH[_2_] Excel Programming 5 January 23rd 06 03:58 AM
Excel cut/Paste Problem: Year changes after data is copy and paste Asif Excel Discussion (Misc queries) 2 December 9th 05 05:16 PM
Copy and Paste macro needs to paste to a changing cell reference loulou Excel Programming 0 February 24th 05 10:29 AM


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