Copy cell from various tabs

detolicious

Board Regular
Joined
Sep 30, 2009
Messages
52
Hi there,

So I've got this code embedded in a userform that allows me to run a summary sheet. What it does is, open all excel files in a specified folder, copy a cell and paste it on the summary sheet, save the workbook and open the next one.

This way I can get data from hundreds of files by only clicking one button instead of opening every single file manually.

I am at an impasse now though, because it will only open the first tab and not other tabs if there are any. I was wondering if I can implement a line that says to check for other tabs and do the same there...

see the code below:

Code:
Sub YouBroughtThisOnYourself()
Dim oWbk As Workbook
Dim sFil As String
Dim sPath As String
Dim i As Integer

sPath = "L:\_Everyone\Dino\DEV0_Windwalk\livefeed"
ChDir sPath
sFil = Dir(sPath & "\*.xls")
Do While sFil <> ""
Set oWbk = Workbooks.Open(sPath & "\" & sFil)

ActiveSheet.Range("D6").Select
Selection.Copy
Workbooks("ww1.xls").Activate
Range("A1").Select
Do Until ActiveCell.Row = 65536
    Selection.End(xlDown).Select
Loop
Selection.End(xlUp).Select
ActiveCell.Offset(1, 0).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=True
Application.CutCopyMode = False

oWbk.Save
oWbk.Close
sFil = Dir
Loop

Application.Wait Now + TimeSerial(0, 0, 5)

then it repeats itself with another Cell, D7 for example.

Any ideas?

Thanks,
Dino
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
try changing
Code:
ActiveSheet.Range("D6").Select
Selection.Copy
Workbooks("ww1.xls").Activate
Range("A1").Select
Do Until ActiveCell.Row = 65536
    Selection.End(xlDown).Select
Loop
Selection.End(xlUp).Select
ActiveCell.Offset(1, 0).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=True
Application.CutCopyMode = False
to
Code:
For Each WS In Sheets
        WS.Activate
Range("D6").Select
Selection.Copy
Workbooks("ww1.xls").Activate
Range("A1").Select
Do Until ActiveCell.Row = 65536
    Selection.End(xlDown).Select
Loop
Selection.End(xlUp).Select
ActiveCell.Offset(1, 0).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=True
Application.CutCopyMode = False
Next WS
 
Upvote 0
works perfectly :biggrin: at least the first set - but the following tabs aren't called. I keep getting "next without for"-error message.
 
Upvote 0
nevermind, found a way around it.

Code:
Sub YouBroughtThisOnYourself()

Dim oWbk As Workbook
Dim WS As Worksheet
Dim sFil As String
Dim sPath As String
Dim i As Integer
 
sPath = "L:\Dino\DEV0_Windwalk\livefeed"
ChDir sPath
sFil = Dir(sPath & "\*.xls")
Do While sFil <> ""
Set oWbk = Workbooks.Open(sPath & "\" & sFil)
 
For Each WS In Sheets
        WS.Activate
Range("D6").Select
Selection.Copy
Workbooks("ww1.xls").Activate
Range("A1").Select
Do Until ActiveCell.Row = 65536
    Selection.End(xlDown).Select
Loop
Selection.End(xlUp).Select
ActiveCell.Offset(1, 0).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=True
Application.CutCopyMode = False
Next WS
 
Application.Wait Now + TimeSerial(0, 0, 5)
 
oWbk.Save
oWbk.Close
sFil = Dir
Loop
 
sPath = "L:\Dino\DEV0_Windwalk\livefeed"
ChDir sPath
sFil = Dir(sPath & "\*.xls")
Do While sFil <> ""
Set oWbk = Workbooks.Open(sPath & "\" & sFil)
 
For Each WS In Sheets
        WS.Activate
Range("D7").Select
Selection.Copy
Workbooks("ww1.xls").Activate
Range("B1").Select
Do Until ActiveCell.Row = 65536
    Selection.End(xlDown).Select
Loop
Selection.End(xlUp).Select
ActiveCell.Offset(1, 0).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=True
Application.CutCopyMode = False
Next WS
 
Application.Wait Now + TimeSerial(0, 0, 5)

only downside, it's also taking the hidden tabs - not too bad though :biggrin: thanks 'pboltonchina' for the help, much appreciated!
 
Upvote 0

Forum statistics

Threads
1,224,566
Messages
6,179,553
Members
452,928
Latest member
101blockchains

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