標題:
[發問]
如何用excel的巨集寫一個撈資料至另一個工作表,求解
[打印本頁]
作者:
wantknow55
時間:
2013-3-24 18:44
標題:
如何用excel的巨集寫一個撈資料至另一個工作表,求解
現在有一個excel檔裡面有sheet1、sheet2,兩個工作表
sheet1的內容,想用一個Inputbox於輸入sheet1的編號後將該編號之同一列全部
複製或撈至sheet2,每次撈完皆會自動換列,求解。
[attach]14435[/attach] ←此為sheet1之內容
[attach]14436[/attach]
[attach]14437[/attach]
求專家解,拜託了orz
作者:
kimbal
時間:
2013-3-25 01:18
Sub test()
Dim strID As String
Dim intSheet1RowCnt
Dim intSheet1RowCnter
Dim rngSheet1Target
Dim intSheet2RowCnt
strID = InputBox("輸入編號")
intSheet1RowCnt = Sheets("Sheet1").Range("A1").End(xlDown).Row
For intSheet1RowCnter = 2 To intSheet1RowCnt
If Sheets("Sheet1").Range("A1").Offset(intSheet1RowCnter, 2) = strID Then
Set rngSheet1Target = Sheets("Sheet1").Range("A1").Offset(intSheet1RowCnter)
With Sheets("Sheet2")
intSheet2RowCnt = .Range("A65536").End(xlUp).Row + 1
.Cells(intSheet2RowCnt, 1) = rngSheet1Target
.Cells(intSheet2RowCnt, 2) = rngSheet1Target.Offset(0, 1)
.Cells(intSheet2RowCnt, 3) = rngSheet1Target.Offset(0, 2)
End With
End If
Next
End Sub
複製代碼
作者:
GBKEE
時間:
2013-3-25 08:57
回復
1#
wantknow55
Option Explicit
Sub Ex()
Dim BoxRow As Variant, BoxWord As Variant
BoxWord = Application.InputBox("輸入編號", Type:=3)
If BoxWord = False Then Exit Sub
BoxRow = Application.Match(BoxWord, Sheets("Sheet1").Columns(3), 0)
'Match函數傳回在Sheets("Sheet1").Columns(3)中第一個=編號的位置號數
If IsNumeric(BoxRow) Then 'Match函數有找到傳回數字,反之傳回錯誤值
With Sheets("Sheet2").Range("A65536").End(xlUp).Offset(1)
.Resize(, 3) = Sheets("Sheet1").Cells(BoxRow, 1).Resize(, 3).Value
End With
Else
MsgBox BoxWord & " 編號找不到 !!"
End If
End Sub
複製代碼
歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)