basic excel 2003 macro no longer works in excel 2007

umy

New Member
Joined
Sep 21, 2010
Messages
7
I always used the below simple macro for combining data from multiple sheets into one and it worked a treat. However, we have now upgraded to from office 2003 to office 2007 and it has stopped working. Can you let me know what I need to change and if possible, maybe even make the change for me as my excel is as good as my Klingon, not very good at all J
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
Thank you
<o:p></o:p>
<o:p></o:p>
Sub Get_Value_From_All()
<o:p></o:p>
Dim wbSource As Workbook
Dim wbThis As Workbook
Dim rToCopy As Range
Dim rNextCl As Range
Dim lCount As Long
Dim bHeaders As Boolean
Dim n As Long
Dim i As Long
Dim wsFrom As Worksheet
Dim wsTo As Worksheet
<o:p></o:p>
With Application
.ScreenUpdating = False
.DisplayAlerts = False
.EnableEvents = False
<o:p></o:p>
On Error Resume Next
Set wbThis = ThisWorkbook

search:
With .FileSearch
.NewSearch
'Change path to suit
.LookIn = "C:\newtest\"
.FileType = msoFileTypeExcelWorkbooks
If .Execute > 0 Then 'Workbooks in folder
For lCount = 1 To .FoundFiles.Count ' Loop through all.
'Open Workbook x and Set a Workbook variable to it
Set wbSource = Workbooks.Open(Filename:=.FoundFiles(lCount), UpdateLinks:=0)
For i = 1 To wbSource.Worksheets.Count - 1
Set wsFrom = wbSource.Worksheets(i)
Set wsTo = wbThis.Worksheets(i)
Set rToCopy = wsFrom.Range("B2", wsFrom.Range("B" & Rows.Count).End(xlUp)).Resize(, 20)
Set rNextCl = wsTo.Cells(Rows.Count, 2).End(xlUp).Offset(1, 0)
If rNextCl.Row > 2 Then
rToCopy.Offset(1, 0).Resize(rToCopy.Rows.Count - 1, rToCopy.Columns.Count).Copy rNextCl
'no headers so copy
Else
rToCopy.Copy wsTo.Range("B2")
End If
Next i
wbSource.Close False 'close source workbook
Next lCount
Else
MsgBox "No workbooks found"
End If
End With
<o:p></o:p>
For i = 1 To wbThis.Worksheets.Count - 1
With wbThis.Worksheets(i)
n = .Cells(Rows.Count, 2).End(xlUp).Row
.Range("A2:A" & n).ClearContents
.Range("A3").Value = 1
.Range("A3:A" & n).DataSeries , Type:=xlLinear, Step:=1
End With
Next i
<o:p></o:p>
On Error GoTo 0
.ScreenUpdating = True
.DisplayAlerts = True
.EnableEvents = True
End With
<o:p></o:p>
End Sub
 
Nope, still fails for me with the subscript error and if there is more than one sheet in the folder, it doesn't move onto the second one.

May i email you the sheets that I am using?

Many thanks
 
Upvote 0
That will happen if there are fewer worksheets in wbThis than there are in wbSource (whose worksheets you are looping around).
 
Upvote 0

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top