PC Review


Reply
Thread Tools Rate Thread

Copy specific cells to new rows

 
 
=?Utf-8?B?S2F0aHkgLSBMb3Z1bGxv?=
Guest
Posts: n/a
 
      26th Oct 2007
I am looking for some help copying some specific cells from one worksheet to
the last row on another sheet. Basically I have various which I have named.
I want to a macro that will take these cells and paste them to a new row.
For example on Sheet one I may have the following Named cells

C2 = Name
D3 = Date
C4 = Company
E6 = State

I then want a macro to past these in the last available row, sequentially in
each column starting in column A. For example, assuming the last available
row is 20, the Sheet1.C2 would copy to Sheet2A20, Sheet1.D3 to Sheet2.B20,
Sheet1.C4 TO Sheet2.C20 and sheet1.E6 to Sheet2.D20.

Any help would be greatly appreciated.


 
Reply With Quote
 
 
 
 
Bill Renaud
Guest
Posts: n/a
 
      26th Oct 2007
Try the following code. Note: If Sheet2 is empty, it will copy to row 2,
however.

Public Sub CopyCells()
Dim wb As Workbook
Dim ws1 As Worksheet 'Source worksheet for data to copy.
Dim ws2 As Worksheet 'Destination worksheet.

Dim rngName As Range 'Named ranges.
Dim rngDate As Range
Dim rngCompany As Range
Dim rngState As Range

Dim lngNextAvailableRow As Long

Set wb = ActiveWorkbook
Set ws1 = Worksheets("Sheet1")
Set ws2 = Worksheets("Sheet2")

With wb
Set rngName = .Names("Name").RefersToRange
Set rngDate = .Names("Date").RefersToRange
Set rngCompany = .Names("Company").RefersToRange
Set rngState = .Names("State").RefersToRange
End With

With ws2
With .UsedRange
lngNextAvailableRow = .Row + .Rows.Count
End With
'Now copy cells.
.Cells(lngNextAvailableRow, 1).Value = rngName.Value
.Cells(lngNextAvailableRow, 2).Value = rngDate.Value
.Cells(lngNextAvailableRow, 3).Value = rngCompany.Value
.Cells(lngNextAvailableRow, 4).Value = rngState.Value
End With
End Sub


--
Regards,
Bill Renaud



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to copy specific number of rows from cells to cells? Eric Microsoft Excel Programming 9 30th Apr 2010 08:11 AM
Copy / paste only specific rows Benjamin Microsoft Excel Misc 3 11th Apr 2008 03:14 PM
copy specific rows to a new sheet =?Utf-8?B?a2lt?= Microsoft Excel Programming 14 30th Apr 2007 05:03 PM
COPY AND PASTE SPECIFIC ROWS =?Utf-8?B?SEVSTkFO?= Microsoft Excel Misc 2 17th Aug 2006 07:32 PM
Copy rows with a specific value in column A Gert-Jan Microsoft Excel Programming 7 23rd Jun 2006 05:13 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:54 PM.