sdfsdf sddsf fggg dfgfg sdfsdf
Copy data from files in the current directoryDim CurrentFileName As StringDim tempCell, tempCell2 As VariantDim CountIndex As IntegerDim rowCountIndex, totalRowCount As IntegerSet tempCell = Sheets("MENU").Range("Start_File").Offset(1, 0)CurrentFileName = ActiveWorkbook.Name'Clean all old records ------------------------------- Dim i As Integer Sheets("Template").Select Sheets("Template").Range("A3:P3").Select For i = 1 To 10 Range(Selection, Selection.End(xlDown)).Select Next i Range(Selection, Selection.End(xlDown)).ClearContents ActiveSheet.Calculate'Clean all old records -------------------------------CountIndex = 0Do While Not IsEmpty(tempCell)Application.CutCopyMode = TrueWorkbooks.Open Filename:=ActiveWorkbook.Path & "\" & tempCell.Text'Copy BS DataWindows(tempCell.Text).Activate' To deal with only one row caserowCountIndex = 0Set tempCell2 = Sheets("Template").Range("A5")Do While Not IsEmpty(tempCell2)rowCountIndex = rowCountIndex + 1Set tempCell2 = tempCell2.Offset(1, 0)LoopSheets("Template").Range("A5:P5").SelectIf rowCountIndex = 1 ThenSelection.CopyElseRange(Selection, Selection.End(xlDown)).CopyEnd IfWindows(CurrentFileName).ActivateSheets("Template").Range("A2").SelectIf CountIndex <> 0 ThenSheets("Template").Range("A2").End(xlDown).Offset(1, 0).SelectElseSheets("Template").Range("A2").Offset(1, 0).SelectEnd IfSelection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=FalseCountIndex = CountIndex + 1'Copy IS DataWindows(tempCell.Text).Activate' To deal with only one row caserowCountIndex = 0Set tempCell2 = Sheets("Template").Range("W5")Do While Not IsEmpty(tempCell2)rowCountIndex = rowCountIndex + 1Set tempCell2 = tempCell2.Offset(1, 0)LoopSheets("Template").Range("W5:AL5").SelectIf rowCountIndex = 1 ThenSelection.CopyElseRange(Selection, Selection.End(xlDown)).CopyEnd IfWindows(CurrentFileName).ActivateIf CountIndex <> 0 ThenSheets("Template").Range("A2").End(xlDown).Offset(1, 0).SelectElseSheets("Template").Range("A2").Offset(1, 0).SelectEnd IfSelection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=FalseWindows(tempCell.Text).ActivateApplication.CutCopyMode = FalseActiveWindow.CloseSet tempCell = tempCell.Offset(1, 0)CountIndex = CountIndex + 1LoopEnd Sub .msgcontent .wsharing ul li { text-indent: 0; } 分享 Facebook Plurk YAHOO!
好站連結:http://tw.myblog.yahoo.com/beck46919363