문제 설명
공개 함수의 VBA 런타임 오류 ‑2147319767(80028029) (VBA Run‑time error ‑2147319767 (80028029) in Public Function)
이 오류는 오늘 다음 코드에서 나타납니다.
Public lngLast_CS_Sheet As Long
Public lngCS1_Index As Long
Public lngCSLast_Index As Long
6Public Function num_CSx_Sheets() 'Function to find total number of CS Sheets
Dim w As Long, cs As Long
For w = 1 To Sheets.Count
cs = cs ‑ CBool(UCase(Left(Sheets(w).Name, 2)) = "CS")
Next w
num_CSx_Sheets = cs
End Function
이 함수는 몇 년 동안 제대로 작동했지만 w = 17 & cs = 4
CS 시트의 범위에서 사용자의 잘못된 이름 지정을 확인했지만 문제를 찾을 수 없습니다.
함수는 다음 코드에 의해 호출됩니다.
Sub BoMLookUpMaterials_2019_Rev_B()
'
' BoMSearch CS Sheets Macro ‑ Modified 11/01/19 ‑ PRS
'
Dim FirstSheet As Integer
Dim LastSheet As Integer
Dim LastRow As Integer
Dim FirstRow As Integer
Dim ItemQTY As Single
Dim sSheetName As String
Dim sItemName As String
With ActiveSheet
LastRow = Cells(.Rows.Count, "Q").End(xlUp).Row 'Find last row of BoM (Qty) Col Q
End With
'
sSheetName = ActiveSheet.Name 'Get sheet name of active Database sheet
'
lngLast_CS_Sheet = num_CSx_Sheets() 'Find total number of CS sheets
lngCS1_Index = Sheets("CS1").Index 'CS1 Sheet Index No.
lngCSLast_Index = Sheets("CS" & lngLast_CS_Sheet).Index 'Last CS Sheet Index No.
Select Case sSheetName 'Determines which BoM sheet initiated Update BOM procedure
나는 경험 많은 VBA 프로그래머가 아니며 이것이 왜 지금 발생하는지 이해할 수 없습니다. 누군가 나에게 올바른 방향을 알려줄 수 있습니까?
참조 솔루션
방법 1:
I don't think this is a code issue as further testing by making lngLast_CS_Sheet equal the number of CS sheets in the workbook, the code runs without error. This error has only occurred in this workbook and not others with exactly the same code modules. Therefore I conclude this to be a user induced error somewhere within the workbook which I will tray & track down