Rows.Count
을 사용할 때 런타임 오류 1004가 계속 발생합니다. 아래 코드를 처음 실행할 때 일반적으로 발생하지만 재설정하고 다시 실행하면 작동합니다.Rows.Count가 런타임 오류 1004를 생성합니다.
은 :
LastRow = Cells(Rows.Count, 4).End(xlUp).Row
안정적으로 실행하려면이 코드를 얻기에 어떤 도움을 크게 감상 할 수있다! 정수로가 너무 많은 행이, Dim LastRow As Integer
Dim LastRow As Long
에
Private Sub ImportAPRData_Click()
'Declare variables for columns in "Projects" spreadsheet in Approved Reliability Projects Workbook (Excel)
Dim orgSheetCol(13) As String
orgSheetCol(0) = "$E$" 'Project Title
orgSheetCol(1) = "$D$" 'Circuit Tag
orgSheetCol(2) = "$F$" 'District
orgSheetCol(3) = "$G$" 'State
orgSheetCol(4) = "$M$" 'Date recieved
orgSheetCol(5) = "$J$" 'Planned Capital Cost
orgSheetCol(6) = "$X$" 'Actual Capital Cost
orgSheetCol(7) = "$U$" 'Capital work completed date
orgSheetCol(8) = "$K$" 'Planned O&M Cost
orgSheetCol(9) = "$Y$" 'Actual O&M Cost
orgSheetCol(10) = "$V$" 'O&M work completed date
orgSheetCol(11) = "$AD$" 'Path to RWP file
orgSheetCol(12) = "I" 'Investment Reason
'Declare variables for cell values attained from APR spreadsheet
Dim orgSheetvalues(13) As Variant
orgSheetvalues(0) = "" 'Project Title
orgSheetvalues(1) = "" 'Circuit Tag
orgSheetvalues(2) = "" 'District
orgSheetvalues(3) = "" 'State
orgSheetvalues(4) = "" 'Date recieved
orgSheetvalues(5) = "" 'Planned Capital Cost
orgSheetvalues(6) = "" 'Actual Capital Cost
orgSheetvalues(7) = "" 'Capital work completed date
orgSheetvalues(8) = "" 'Planned O&M Cost
orgSheetvalues(9) = "" 'Actual O&M Cost
orgSheetvalues(10) = "" 'O&M work completed date
orgSheetvalues(11) = "" 'RWP File Path
orgSheetvalues(12) = "" 'Investment Reason
'Declare & Set Variables for opening & working with Excel Wrokbook/worksheet (Approved Relaibility Projects/Projects)
Dim xls As Excel.Application
Dim wkb As Excel.Workbook
Dim wks As Excel.Worksheet
Set xls = New Excel.Application
'Delcare & set variables for loops, excel row, cell numbers, etc.
Dim rownumber As Integer
rownumber = 3
Dim rowstring As String
Dim cellstring As String
Dim i As Integer
'Declare & set variable to see if RWP already exists in table
Dim tablecheck As Integer
tablecheck = 0
'Declare variable for Capital and O&M Costs/completion dates conditions
Dim Condition1 As Boolean
Dim Condition2 As Boolean
Dim Condition3 As Boolean
Dim Condition4 As Boolean
Dim Condition5 As Boolean
Dim Condition6 As Boolean
Dim Condition7 As Boolean
Dim Condition8 As Boolean
Dim LastRow As Integer
'Open Approved Reliability Projects Workbook & set worksheet to "Projects"
xls.Visible = True
xls.UserControl = True
Set wkb = xls.Workbooks.Open("\\pacificorp.us\dfs\SLCCO\SHR02\PD\POWER\AreaSystemFiles\UT\Park_City_Office\Reliability\RWP_Goal_Tracking\Approved Reliability Projects v5.xlsm", ReadOnly:=True, UpdateLinks:=False)
Set wks = wkb.Worksheets("Projects")
'Find row # for last populated row
LastRow = Cells(Rows.Count, 4).End(xlUp).Row 'For some reason it keeps giving me an error here!!!!
'For each row in APR spreadsheet get info, then make sure all criteria are met, then check to see if it already exists in table, if not insert into table
For rownumber = 3 To LastRow
rowstring = CStr(rownumber)
'Pull information from specified row in APR Spreadsheet
For i = 0 To 12
cellstring = orgSheetCol(i) & rowstring
orgSheetvalues(i) = wks.Range(cellstring).Value
If IsError(orgSheetvalues(i)) Then
orgSheetvalues(i) = wks.Range(cellstring).Text
End If
Next i
'Check to make sure that there are planned costs and completion dates before inserting into rwpT Table
Condition1 = orgSheetvalues(5) <> "" And (orgSheetvalues(7) <> "" And orgSheetvalues(7) <> "#") And orgSheetvalues(11) Like "\\*"
Condition2 = orgSheetvalues(5) = "" And orgSheetvalues(7) = "" And orgSheetvalues(11) Like "\\*"
Condition3 = orgSheetvalues(8) <> "" And orgSheetvalues(10) <> "" And orgSheetvalues(10) <> "N/A"
Condition4 = orgSheetvalues(8) = "" And orgSheetvalues(10) = ""
Condition5 = Condition1 And Condition3
Condition6 = Condition1 And Condition4
Condition7 = Condition1 And Condition3
Condition8 = (Condition5 Or Condition6) Or Condition7
If Condition8 Then
tablecheck = DCount("PlanTitle", "rwpT", "PlanTitle = '" & orgSheetvalues(0) & "'") 'check rwp table to see if plan is already there
'If plan is not there insert into rwpT Table
If tablecheck = 0 Then
CurrentDb.Execute "INSERT INTO rwpT (PlanTitle, Circuit, OpArea, State, InvestmentReason, ApprovalDate, PlanCapitalCost, ActualCapitalCost, CapitalWorkCompDate, PlanOMCost, ActualOMCost, OMWorkCompDate, File) Values ('" & orgSheetvalues(0) & "', '" & orgSheetvalues(1) & "', '" & orgSheetvalues(2) & "', '" & orgSheetvalues(3) & "','" & orgSheetvalues(12) & "', '" & orgSheetvalues(4) & "', '" & orgSheetvalues(5) & "', '" & orgSheetvalues(6) & "', '" & orgSheetvalues(7) & "', '" & orgSheetvalues(8) & "', '" & orgSheetvalues(9) & "', '" & orgSheetvalues(10) & "','" & orgSheetvalues(11) & "')"
End If
End If
Next rownumber
'Close Approved Reliability Projects Workbook & remove all handles to it
wkb.Close False 'Close workbook. False is so that it doesn't save
Set wks = Nothing
Set wkb = Nothing
xls.Quit
Set xls = Nothing
End Sub
당신의 방법/특성을 규정하는 것이
그렇게 말하고 선 'Integer' 오류는 오류 1004가 아닌 오류 6 ("Overflow")이됩니다. 따라서 Integer를 Long으로 변경하는 것이 매우 바람직하지만 오류가 발생하지는 않습니다. 오류. – YowE3K