![]() |
Using VBA to copy data into another worksheet ???
I have an Excel workbook with 5 worksheets (individuals fill out their appropriate worksheet columns A to AW). There is a Totals worksheet in the workbook that has a command click update button. The update button starts with the 1st individual worksheet and using column A (until column A is empty) copies the information onto the Totals worksheet....it then moves to the next individual worksheet and does the same thing. The problem is that it appears vba will only copy data from column A to Z, what do I need to do in order to pick up the remaining 23 columns that contain data?
|
Using VBA to copy data into another worksheet ???
VBA recognizes all columns in a worksheet. . . . at least in 2007 it
does. Sub copycols() Sheets("Sheet1").Range("A1:AZ12").Copy _ Destination:=Sheets("Sheet2").Range("A1") End Sub Gord On Mon, 20 May 2013 12:19:16 -0700 (PDT), wrote: I have an Excel workbook with 5 worksheets (individuals fill out their appropriate worksheet columns A to AW). There is a Totals worksheet in the workbook that has a command click update button. The update button starts with the 1st individual worksheet and using column A (until column A is empty) copies the information onto the Totals worksheet....it then moves to the next individual worksheet and does the same thing. The problem is that it appears vba will only copy data from column A to Z, what do I need to do in order to pick up the remaining 23 columns that contain data? |
Using VBA to copy data into another worksheet ???
On Monday, May 20, 2013 3:19:16 PM UTC-4, wrote:
I have an Excel workbook with 5 worksheets (individuals fill out their appropriate worksheet columns A to AW). There is a Totals worksheet in the workbook that has a command click update button. The update button starts with the 1st individual worksheet and using column A (until column A is empty) copies the information onto the Totals worksheet....it then moves to the next individual worksheet and does the same thing. The problem is that it appears vba will only copy data from column A to Z, what do I need to do in order to pick up the remaining 23 columns that contain data? That seems to work if I specify the ending row, which is unknown. My code is: Private Sub cmdUpdate_Click() Dim w As String Dim x As String Dim y As String Dim z As String Dim lCount As Long Dim lresult As Long Dim lcellrangenumeric As Long Dim lColIndex As Long Dim lSheetIndex As Integer With Worksheets("Total") lCount = 3 ' start row value While Len(.Range("A" & CStr(lCount))) 0 For lColIndex = Asc("A") To Asc("AW") ' column value .Range(Chr(lColIndex) & CStr(lCount)).Value = "" Next lColIndex lCount = lCount + 1 'next row Wend End With For Each ws In Worksheets With ws If InStr(ws.Name, ".") 0 Then ' does this worksheet contain someone's name? ' transfer data lCount = 2 ' start row value While Len(.Range("A" & CStr(lCount))) 0 lresult = FindnextAvail ' first available row in the Totals sheet For lColIndex = Asc("A") To Asc("AW") ' column value Worksheets("Total").Range(Chr(lColIndex) & CStr(lresult)).Value = .Range(Chr(lColIndex) & CStr(lCount)).Value Next lColIndex lCount = lCount + 1 'next row Wend End If End With Next ws End Sub Private Function FindnextAvail() Dim lCount As Long With Worksheets("Total") lCount = 3 ' start row value While Len(.Range("A" & CStr(lCount))) 0 lCount = lCount + 1 'next row Wend End With FindnextAvail = lCount End Function |
All times are GMT +1. The time now is 02:58 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com