ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Macros (https://www.excelbanter.com/excel-discussion-misc-queries/208044-macros.html)

TX_AGS

Macros
 
I would like to create a macro that copies and pastes data from 1 worksheet
to another, but each time it is run it records the data in a new row. Any
help appreciated.

Mike H

Macros
 
Given that you haven't over-explained your question here's a solution you may
be able to build on. It's worksheet code and goes in the sheet you want to
copy the data from

Sub stance()
Dim MyRange As Range
Dim CopyRange As Range
lastrow = Cells(Cells.Rows.Count, "A").End(xlUp).Row
Set MyRange = Range("A1:A" & lastrow)
For Each C In MyRange
If UCase(C.Value) = "SOMEVALUE" Then
If CopyRange Is Nothing Then
Set CopyRange = C.EntireRow
Else
Set CopyRange = Union(CopyRange, C.EntireRow)
End If
End If
Next
If Not CopyRange Is Nothing Then
lastrow = Sheets("Sheet2").Cells(Cells.Rows.Count, "A").End(xlUp).Row
CopyRange.Copy Sheets("Sheet2").Range("A" & lastrow + 1)
End If

End Sub

Mike

"TX_AGS" wrote:

I would like to create a macro that copies and pastes data from 1 worksheet
to another, but each time it is run it records the data in a new row. Any
help appreciated.


Gary''s Student

Macros
 
The following macro will copy the first row of the source sheet to the next
available row of the destination sheet:

Sub ags()
Dim ss As Worksheet, sd As Worksheet
Set ss = Sheets("source")
Set sd = Sheets("destination")
n = sd.Cells(Rows.Count, "A").End(xlUp).Row + 1
ss.Range("1:1").Copy Destination:=sd.Range("A" & n)
End Sub

--
Gary''s Student - gsnu200810


"TX_AGS" wrote:

I would like to create a macro that copies and pastes data from 1 worksheet
to another, but each time it is run it records the data in a new row. Any
help appreciated.


Sheeloo[_3_]

Macros
 
Try
Sub copy1()
Dim lastRow As Long
lastRow = Worksheets("Sheet2").Cells(Worksheets("Sheet2").Ro ws.Count,
"A").End(xlUp).Row
Worksheets("Sheet1").UsedRange.Copy
Worksheets("Sheet2").Activate
Range("A" & (lastRow + 1)).Select
ActiveSheet.Paste
End Sub
"TX_AGS" wrote:

I would like to create a macro that copies and pastes data from 1 worksheet
to another, but each time it is run it records the data in a new row. Any
help appreciated.



All times are GMT +1. The time now is 12:38 PM.

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