標題:
[發問]
資格結入表格VBA
[打印本頁]
作者:
missbb
時間:
2015-2-3 21:57
標題:
資格結入表格VBA
[attach]20191[/attach]可否用VBA, 將下列資料, 結合入表格內, 自動產生以NAME為名稱的SHEET?
Name Dept Post
A 1 Clerk
B 2 Senior Clerk
C 3 Officer
下列為SHEET A, 將NAME,DEPT, POST內容顯示, 並有下列RECORD,IN,OUT, REMARKS的按格:
Name A Post Clerk
Dept 1
Record In Out Remarks
作者:
stillfish00
時間:
2015-2-4 11:29
回復
1#
missbb
執行前只有data工作表
Sub Test()
Dim i As Long, bAlert As Boolean
Dim sName As String, sDept As String, sPost As String
Dim wsTemp As Worksheet
'先建立暫時的工作表範本,供之後Copy
Set wsTemp = Sheets.Add(After:=Sheets(Sheets.Count))
With wsTemp
.Cells(1, 1).Value = "Name"
.Cells(2, 1).Value = "Dept"
.Cells(1, 5).Value = "Post"
With .Cells(4, 1)
.Resize(1, 4).Value = Array("Record", "In", "Out", "Remarks")
.Resize(5, 4).Borders.LineStyle = xlContinuous
End With
End With
'對 data 中項目建立各分頁
With Sheets("data")
For i = 2 To .Cells(.Rows.Count, 1).End(xlUp).Row
sName = .Cells(i, 1).Value
sDept = .Cells(i, 2).Value
sPost = .Cells(i, 3).Value
wsTemp.Copy After:=Sheets(Sheets.Count)
With Sheets(Sheets.Count)
.Name = sName
.Cells(1, 2).Value = sName
.Cells(2, 2).Value = sDept
.Cells(1, 6).Value = sPost
End With
Next
End With
bAlert = Application.DisplayAlerts
Application.DisplayAlerts = False
wsTemp.Delete
Application.DisplayAlerts = bAlert
End Sub
複製代碼
作者:
missbb
時間:
2015-2-5 22:09
回復
2#
stillfish00
多謝指導!
歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)