標題:
[發問]
請問如何更改程式變成可新增紀錄
[打印本頁]
作者:
samneng
時間:
2015-12-11 13:27
標題:
請問如何更改程式變成可新增紀錄
請問各位大大及前輩們
以下程式試著用Excel VBA編寫後發現只能新增在同一列紀錄....請問如何變更後可以無限新增紀錄!??
此部分是用在按鈕的巨集內 (目前只知道似乎與" Set NewRecord = myTable.Rows(1).Offset(myTable.Rows.Count) "有關但不知如何變更
請各位大大前輩們幫忙看看... 謝謝!!
Sub 新增紀錄()
Dim formsheet As Worksheet, myTable As Range
Dim NewRecord As Range, i As Long
Dim addressList()
Set formsheet = Sheets("輸入資料")
Set myTable = _
ThisWorkbook.Names("工作交接事項").RefersToRange
'將輸入用與轉寫目標位置的表格設定給變數
addressList = _
Array("C4", "C5", "C6", "C7", "F5", "F6", "F7", "C8", "C9", "C10")
'將要轉寫的儲存格編號儲存在陣列內
Set NewRecord = myTable.Rows(1).Offset(myTable.Rows.Count)
'取得紀錄的新增位置
For i = 0 To UBound(addressList)
NewRecord.Cells(1, i + 1).Value = _
formsheet.Range(addressList(i)).Value
Next
End Sub
作者:
samneng
時間:
2015-12-14 18:03
標題:
RE: 請問如何更改程式變成可新增紀錄
附上詳細附件待請各位大大幫忙確認是否哪邊編寫有誤導至無法新增...謝謝!!
Sub 新增紀錄()
Dim formsheet As Worksheet, myTable As Range
Dim NewRecord As Range, i As Long
Dim addressList()
Set formsheet = Sheets("輸入資料")
'Application.Goto _
'ThisWorkbook.Names("工作交接事項").RefersToRange
'從名稱選取活頁簿等級的儲存格範圍
Set myTable = _
ThisWorkbook.Names("工作交接事項").RefersToRange
'將輸入用與轉寫目標位置的表格設定給變數
'Range("C4").Value = 1
addressList = _
Array("C4", "C5", "C6", "C7", "F5", "F6", "F7", "C8", "C9", "C10")
'將要轉寫的儲存格編號儲存在陣列內
Set NewRecord = Worksheets("工作交接事項").Range("B:D")
'取得紀錄的新增位置
For i = 0 To UBound(addressList)
NewRecord.Cells(1, i + 1).Value = _
formsheet.Range(addressList(i)).Value
Next
End Sub
複製代碼
歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)