A
Anita
I'm setting up a webshop and using Excel to put in the products.
I've got seperate workbooks for my 20 product-groups (20 excel
documents),
and each group is devided in brands (a min. of 5 brands per product
group),
which are in worksheets. I've got 20 seperate workbooks (eg
group1.xls; group2.xls; group3.xls etc.)
Each of those workbook is devided into brands bij using worksheets.
I would like to make a file that imports all the data from all the
worksheets, without me having to save each worksheet into a different
text file (over 100!).
I've tried to copy the data and past it as a link, but when a row is
added in the original document,
updating the link doesn't add the added row.
I've tried to import from text files, it does add added rows, but I've
got
to save all my worksheets as text files (over 100).
I placed this in a wrong newsgroup for windows users but i got the
following Marco from someone:
Public Function LastRow(sh As Worksheet)
On Error Resume Next
LastRow = sh.Cells.Find(What:="*", _
After:=sh.Range("A1"), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
On Error GoTo 0
End Function
Sub MergeSheets()
Dim sh As Worksheet
Dim last As Long
Dim rng As Range
Dim shLast As Long
Worksheets("Master").Cells.ClearContents
Worksheets("Master").Range("a1").Value = "All sheets"
For Each sh In ThisWorkbook.Worksheets
If UCase(sh.Name) <> "MASTER" Then
last = LastRow(Worksheets("Master"))
shLast = LastRow(sh)
Set rng = Worksheets("Master").Cells(last + 1, 1)
sh.Range(sh.Rows(1), sh.Rows(shLast)).Copy Destination:=rng
End If
Next
End Sub
But it shows a runtime error, and Excel want to debug this line:
sh.Range(sh.Rows(1), sh.Rows(shLast)).Copy Destination:=rng
Can anyone help me out here?
I've got seperate workbooks for my 20 product-groups (20 excel
documents),
and each group is devided in brands (a min. of 5 brands per product
group),
which are in worksheets. I've got 20 seperate workbooks (eg
group1.xls; group2.xls; group3.xls etc.)
Each of those workbook is devided into brands bij using worksheets.
I would like to make a file that imports all the data from all the
worksheets, without me having to save each worksheet into a different
text file (over 100!).
I've tried to copy the data and past it as a link, but when a row is
added in the original document,
updating the link doesn't add the added row.
I've tried to import from text files, it does add added rows, but I've
got
to save all my worksheets as text files (over 100).
I placed this in a wrong newsgroup for windows users but i got the
following Marco from someone:
Public Function LastRow(sh As Worksheet)
On Error Resume Next
LastRow = sh.Cells.Find(What:="*", _
After:=sh.Range("A1"), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
On Error GoTo 0
End Function
Sub MergeSheets()
Dim sh As Worksheet
Dim last As Long
Dim rng As Range
Dim shLast As Long
Worksheets("Master").Cells.ClearContents
Worksheets("Master").Range("a1").Value = "All sheets"
For Each sh In ThisWorkbook.Worksheets
If UCase(sh.Name) <> "MASTER" Then
last = LastRow(Worksheets("Master"))
shLast = LastRow(sh)
Set rng = Worksheets("Master").Cells(last + 1, 1)
sh.Range(sh.Rows(1), sh.Rows(shLast)).Copy Destination:=rng
End If
Next
End Sub
But it shows a runtime error, and Excel want to debug this line:
sh.Range(sh.Rows(1), sh.Rows(shLast)).Copy Destination:=rng
Can anyone help me out here?