View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
GS GS is offline
external usenet poster
 
Posts: 364
Default transfer data between worksheets

Try this. It assumes you have selected the first cell on 'Daily' where you
want the data transferred to. By the way, the last cell will be A512, not
A562.

Sub TransferData()
' Transfers data from one sheet to another.
'
' Target sheet (Daily) receives the data starting in row 12,
' and increments 20 rows for each cell of source sheet (Data) value.
'
' Source sheet (Data) values are in rows 5 to 30. (count=26)

Dim Daily As Worksheet, Data As Worksheet
Dim lRow As Long, lSrow As Long

Set Daily = Sheets("Daily")
Set Data = Sheets("Data")

' Select the first target cell ("A12") on 'Daily'
lRow = Selection.Row
' Set the # of the first row on 'Data' containing values to transfer
lSrow = 5 ' ("A5")

Do
Daily.Cells(lRow, 1) = Data.Cells(lSrow, 1)
lRow = lRow + 20
lSrow = lSrow + 1
Loop While lSrow < 31

End Sub



"Qaspec" wrote:

right now i'm using the following code to transfer data. instead of
reapeating the line 26 times is there a way to create this code in a smaller
statement if the data row always increases by 20 and the daily row by 1.

Private Sub Command1_Click()

Dim Daily As Worksheet
Dim Data As Worksheet


Set Daily = Worksheets("Daily")
Set Data = Worksheets("Data")

Daily.Range("A12").Value = Data.Range("A5").Value
Daily.Range("A32").Value = Data.Range("A6").Value
'all the way down to'
Daily. Range("A562").Value=Data.Range("A30").Value



End Sub