UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Cope Data From Column D From Each Worksheet To New Worksheet, Office 2007    
 
   
Kamulegeya
post May 28 2012, 09:38 AM
Post #1

UtterAccess Ruler
Posts: 1,335
From: Kampala,Uganda The Pearl of Africa



Hello Members

I have spread sheet with over 40 worksheets. There is data in column D i am interested in.

I want to copy data from that column, paste it into column A in a new worksheet. What i want say if data for sheet 1 covered A1:A3, Data for sheet2 should start from range A4....down words

My excel vba not good. I have come up with the code below..but it does not work! variable lastRow returns 1 throughout the loop

CODE
Sub CreateList()
Dim wks As Worksheet
Dim wkb As Workbook
Dim newsheet As Worksheet
Dim lastRow As Long
Set wkb = ThisWorkbook
Set newsheet = wkb.Worksheets.Add
newsheet.Name = "Suppliers"
For Each wks In Worksheets
lastRow = wks.Cells(Rows.Count, 1).End(xlUp).Row
Debug.Print lastRow
Range("D1:D" & lastRow).Copy Destination:=newsheet.Range("A1:A" & lastRow)
Next wks
End Sub


Suggestions are highly appreciated

Ronald
Go to the top of the page
 
+
Kamulegeya
post May 28 2012, 10:23 AM
Post #2

UtterAccess Ruler
Posts: 1,335
From: Kampala,Uganda The Pearl of Africa



Hello

Got a solution


CODE
Sub CreateList()
    Dim wks As Worksheet
    Dim wkb As Workbook
    Dim newsheet As Worksheet
    Dim lastRow As Long
    Dim newRow As Long
    Set wkb = ThisWorkbook
    Set newsheet = wkb.Worksheets.Add
    newsheet.Name = "Suppliers"
    ' Start in row 1 on new sheet
    newRow = 1
    For Each wks In Worksheets
        If wks.Name <> newsheet.Name Then
            lastRow = wks.Range("D" & wks.Rows.Count).End(xlUp).Row
            wks.Range("D1:D" & lastRow).Copy _
                Destination:=newsheet.Range("A" & newRow)
            ' Add the number of copied rows to newRow
            newRow = newRow + lastRow
        End If
    Next wks
End Sub



Ronald
Go to the top of the page
 
+

Thank you for your support! Reply to this topicStart new topic

Jump To Forum:
 



RSS Go to Top  ·  Lo-Fi Version Time is now: 20th June 2013 - 03:46 AM