改用Range("A2:A") 也是不行
但想在回圈之前就取得範圍 但也不行會錯
請大大指點出錯誤點


Function FindBaseRow() As Long
Dim i As Long
'Dim getRange As Range
'Set getRange = Range("日期")
Worksheets("資料庫").Activate
i = ActiveCell.Row
For i = ActiveCell.Row To Range("日期").Count <-這行出錯
If IsEmpty(Cells(i, Range("日期").Column)) Then
FindBaseRow = i
Exit Function
End If
Next i
End Function
------------資料庫主要的宣告----------
'建立新資料頁
'設定格式、顏色
'工作頁保護
Sub CreatNewDatabase()
ThisWorkbook.Unprotect jwuue9t2, True, True
Dim newSheetName As String
newSheetName = setName()
Sheets.Add.name = newSheetName '決定名稱
Sheets(newSheetName).Tab.ColorIndex = (Sheets.Count + 1)
setNewDatabaseFormat
ThisWorkbook.Unprotect jwuue9t2, True, True
End Sub
'回傳資料庫的命名
Function setName() As String
setName = "資料庫" & (Sheets.Count + 1)
End Function
'設定格式
Sub setNewDatabaseFormat()
'設定Worksheet格式
With Cells
.Borders(xlEdgeTop).LineStyle = xlContinuous
.Borders(xlEdgeLeft).LineStyle = xlContinuous
.Borders(xlEdgeBottom).LineStyle = xlContinuous
.Borders(xlEdgeRight).LineStyle = xlContinuous
.Borders(xlInsideVertical).LineStyle = xlContinuous
.Borders(xlInsideHorizontal).LineStyle = xlContinuous
.Font.Bold = True
.VerticalAlignment = xlCenter
.HorizontalAlignment = xlCenter
End With
'設定日期格式**********************************************************
With Columns(1)
.name = "日期"
.ColumnWidth = 8
.Interior.ColorIndex = 36
End With
---------自訂的Form---------
Private Sub CommandButton1_Click()
Dim InputRow As Long
Dim year As Long
Dim month As Long
Dim day As Long
Dim yearTransfer As Long
year = Val(DataKeyinForm.日期.Value) / 10000
MsgBox year
month = (Val(DataKeyinForm.日期.Value) - (year * 10000)) / 100
MsgBox month
day = Val(DataKeyinForm.日期.Value) Mod 100
MsgBox day
If (DataKeyinForm.日期.Text = "") Then
MsgBox "日期未輸入"
Exit Sub
End If
InputRow = FindBaseRow '找出要輸入的列
MsgBox FindBaseRow
Cells(InputRow, "A").Value = DataKeyinForm.日期.Value '輸入日期
Cells(InputRow, "B").Value = Week(year, month, day) '輸入週次