PDA

View Full Version : Solved: Copy a row from sheet to sheet



sinus007
02-17-2006, 09:25 AM
Hi,
I'm new to the site. The same applies to VBA. I'm doing a project in Excel and looking for help. I've searched this forum and found bits and pieces of what I'm trying to do. But have hard time to put them together. Hence this cry for help.
I have 9 sheets: 'General View' and 'a' through 'h'. I need to copy any row from any of 'a' - 'h' sheets to the first empty row on 'General View' if there's any change in the original row. Also, the first column on 'General View' should contain the name of the sheet the row was copied from.
I hope my explanation is clear enough, if not - let me know.
Thanks a lot in advance.

AK

mdmackillop
02-17-2006, 11:09 AM
Hi AK,
Welcome to VBAX
I don't think this is too difficult but a little clarification.
What is meant by if there's any change in the original row.
You cannot copy a whole row and paste it where the first cell is reserved for the sheet name. What is the maximum number of columns you are likely to use? We can copy these and paste into column B
Are the rows to be pasted below previous data or into the first available space?
Regards
MD

sinus007
02-17-2006, 12:09 PM
Hi MD,
Thanks for the prompt reply. Sorry for clumsy explanation. Attempt #2
I have 8 columns in sheets 'a' -'h' and 9 in 'General View'.
What I mean by if there's any change in the original row is this:
say I'm entering data into A25:H25 on sheet 'd' which were empty before and, I have data in rows 2-24 on 'General View'. I want cells A25:H25 from 'd' to be pasted into B25:I25 on 'General View' and have A25.value="d"
Hope this clears a bit.
Thanks again. BTW, you have funny quote, well, it'd be funny if it wasn't sad.
AK

mdmackillop
02-17-2006, 12:51 PM
The following code will transfer the data after a change is made in Column H. The same code is pasted into the worksheet module for sheets a-h. Any problems with the way this functions, let me know.

Private Sub Worksheet_Change(ByVal Target As Range)
Dim Tgt As Range
If Target.Column = 8 Then
Set Tgt = Sheets("General View").Cells(Cells.Rows.Count, 1).End(xlUp).Offset(1)
Tgt = ActiveSheet.Name
Tgt.Range("B1:I1") = Target.Offset(, -7).Range("A1:H1").Value
End If
End Sub

sinus007
02-17-2006, 01:27 PM
MD,
Thanks a bunch. It works fine.

AK