hobbiton73
New Member
I wonder whether someone may be able to help me please.
For some time now, I've been trying to put together a macro which allows the user to select Source Files by way of a button select in the 'Destination (Master File). VB is not my strongest subject, so I've not been able to get this to work.
From all the research I've done I started to use the following as a starting point, but there seems to be an inherent bug in the code because although the macro correctly copies the data it adds erroneous lines of data when pasted, so I think I need to start from the beginning.
[pre]
[/pre]
If at all possible, I would be grateful if someone could offer a little guidance on how I may go about achieving the following:
A macro, which for every 'Source File' selected, automatically copies the data from 'Row 5' for the 'Ranges A:AJ and AL:AX' until it reaches a blank row, then closes that file.
Then, with the information that has been copied, I'd be very grateful if someone could then show me how to write the code whereby it searches for the next available blank row in the 'Destination' File, again starting at 'Row 5' for the 'Ranges A:AJ and AL:AX' pasting both the cell value and any formatting or comments into those cells.
Obviously as I copy data from the 'Source Files', I would be most grateful if someone could show me how to make sure that before the data is pasted, it searches for the next available blank row, so in essence each set of data is paste underneath each other.
Many thanks and kind regards
Chris
For some time now, I've been trying to put together a macro which allows the user to select Source Files by way of a button select in the 'Destination (Master File). VB is not my strongest subject, so I've not been able to get this to work.
From all the research I've done I started to use the following as a starting point, but there seems to be an inherent bug in the code because although the macro correctly copies the data it adds erroneous lines of data when pasted, so I think I need to start from the beginning.
[pre]
Code:
Sub CopyData()
Dim wsT As Worksheet
Dim wsF As Worksheet
Dim lRow(1) As Long
Dim iCol As Integer
Dim sFile As String
sFile = Application.GetOpenFilename("Excel Files (*.xls), *.xls")
If sFile = "False" Then
Exit Sub
End If
Set wsT = ThisWorkbook.Sheets("Combined")
Workbooks.Open sFile
Set wsF = ActiveSheet
'get size of data
lRow(0) = wsF.Cells.Find(What:="*", _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious).Row
iCol = wsF.Cells.Find(What:="*", _
SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious).Column
lRow(1) = wsT.Cells.Find(What:="*", _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious).Row + 1
If lRow(1) + lRow(0) > Rows.Count Then
MsgBox "WorkSheet To full to Copy To", vbInformation
Else
wsT.Range("A" & lRow(1) & ":" & Cells(lRow(1) + lRow(0), iCol).Address).Value _
= wsF.Range("A5:" & Cells(lRow(0), iCol).Address).Value
End If
ActiveWorkbook.Close False
End Sub
If at all possible, I would be grateful if someone could offer a little guidance on how I may go about achieving the following:
A macro, which for every 'Source File' selected, automatically copies the data from 'Row 5' for the 'Ranges A:AJ and AL:AX' until it reaches a blank row, then closes that file.
Then, with the information that has been copied, I'd be very grateful if someone could then show me how to write the code whereby it searches for the next available blank row in the 'Destination' File, again starting at 'Row 5' for the 'Ranges A:AJ and AL:AX' pasting both the cell value and any formatting or comments into those cells.
Obviously as I copy data from the 'Source Files', I would be most grateful if someone could show me how to make sure that before the data is pasted, it searches for the next available blank row, so in essence each set of data is paste underneath each other.
Many thanks and kind regards
Chris