標題:
[發問]
關於跳行的問題
[打印本頁]
作者:
starbox520
時間:
2017-1-19 18:56
標題:
關於跳行的問題
請問以下這組程式碼
為何我修改之後一直寫在同一行,不會往下一行寫入了
使用方法是: 開啟"匯出"Excel -> 裡面點選按鈕"匯出"
就會執行裡面的VBA了
VBA會去找叫Rawdata的資料夾->裡面的EXCEL分別打開->取裡面我要的欄位資料 ->一直到最後一個EXCEL
Sub TT()
Dim Mypa$, workName$, brr(1), rr, br
Const sWm As String = "\Rawdata\"
t = Timer
Mypa = ThisWorkbook.Path & sWm
workName = Dir(Mypa & "*.xls")
Sheet1.UsedRange.Offset(1).ClearContents
Application.ScreenUpdating = False
Do Until workName = ""
With GetObject(Mypa & workName)
n = n + 1
With .Sheets("Data")
brr(0) = .Range("a8").Resize(1, 21)
brr(1) = .Range("b19").Resize(1, 20)
End With
.Close False
End With
rr = brr(0): br = brr(1)
With Sheet1
i = .Cells(Rows.Count, 1).End(3).Row + 1
.Range("c" & i).Resize(1, 21) = rr
.Range("x" & i).Resize(1, 20) = br
End With
Erase brr()
workName = Dir
Loop
Application.ScreenUpdating = True
MsgBox "共花" & Format(Timer - t, "0.000") & "秒" _
& Chr(10) & "找到 " & n & "筆資料", vbOKCancel + vbInformation
End Sub
複製代碼
應該要這樣呈現
[attach]26420[/attach]
而不是一直在同一行呈現...(當然最後只有最後找到的一筆的結果)
[attach]26421[/attach]
我寫入的地方在這裡
With Sheet1
i = .Cells(Rows.Count, 1).End(3).Row + 1
.Range("c" & i).Resize(1, 21) = rr
.Range("x" & i).Resize(1, 20) = br
End With
複製代碼
[attach]26422[/attach]
作者:
c_c_lai
時間:
2017-1-19 20:24
回復
1#
starbox520
Option Explicit
Sub TT()
Dim Mypa$, workName$, brr(1), pos As Long
Dim t As Date, n As Long
Const sWm As String = "\Rawdata\"
t = Timer
n = 0
Mypa = ThisWorkbook.Path & sWm
workName = Dir(Mypa & "*.xls")
Sheet1.UsedRange.Offset(1).ClearContents
Application.ScreenUpdating = False
Do Until workName = ""
'With GetObject(Mypa & workName)
With Workbooks.Open(Mypa & workName)
n = n + 1
With .Sheets("Data")
brr(0) = .Range("a8").Resize(1, 21)
brr(1) = .Range("b19").Resize(1, 20)
End With
.Close False
End With
With Sheet1
pos = .Cells(Rows.Count, 3).End(3).Row + 1
.Range("c" & pos).Resize(1, 21) = brr(0)
.Range("x" & pos).Resize(1, 20) = brr(1)
End With
Erase brr()
workName = Dir
Loop
Application.ScreenUpdating = True
MsgBox "共花" & Format(Timer - t, "0.000") & "秒" _
& Chr(10) & "找到 " & n & "筆資料", vbOKCancel + vbInformation
End Sub
複製代碼
作者:
starbox520
時間:
2017-1-19 21:46
回復
2#
c_c_lai
謝謝C大分析
懂了XD
歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)