私はアプリケーション用のVBAを使用してExcelで作業しています。ブック内の特定のデータのセル参照を取得して、セル参照に基づいてdowhileループを構築しようとしています。構成した変数に参照が読み込まれない理由がわかりません。同じワークブックに存在するデータにこの方法を使用したので、他のワークブックへの参照に関連していると思います。MsgBoxがコンソリデータースプレッドシートをアクティブ化する前でも後でも、同じエラー(ランタイム91)が発生します。具体的には、firstDataCell変数とlastDataCell変数が読み込まれていません。この投稿のコードを操作しようとしましたが、どこにも行きませんでした:ExcelVBA-。ブック間のメソッドを見つける
これが私の(切り捨てられた)コードです:
Dim wbConsolidator As Workbook 'Variable to store this workbook
Dim wbQ1Actuals As Workbook 'Variable to store workbook with quarter 1 actuals
Dim wsExist As Boolean 'Variable to store if the worksheet exists in the actuals workbook t/f
Dim searchRange As Range 'Variable to store the range to search for budget data
Dim firstDataCell As Range 'Variable to store first data cell
Dim lastDataCell As Range 'Variable to store the last data cell
Dim tabName As String 'Variable to store employee's tab name
Dim notIn414 As String 'Variable to store employees the VB could not find in 414
Set wbConsolidator = Workbooks("Consolidator.xlsm")
'Store consolidation workbook into variable
Set wbQ1Actuals = Workbooks("(the spreadsheet title")
'Store worbook with Q1 actuals into variable
tabName = calculated based on the employee's name. This functions correctly and the correct tab activates
If wsExist = True Then 'Check if wsExist is false after all loops
wbQ1Actuals.Worksheets(tabName).Activate
Set searchRange = Range("A1", Range("A65536").End(xlUp))
Set firstDataCell = searchRange.Find("Pay Date", LookIn:=xlValues, lookat:=xlWhole)
'Find the first row with budget percentages
Set lastDataCell = searchRange.Find("Total:", LookIn:=xlValues, lookat:=xlWhole)
'Find the sum row to track last row with budget percentages
Else
notIn414 = notIn414 & lastName & "," & firstName & ":"
'Write the employee's name to the error log
End If 'End this test
wbConsolidator.Activate 'Activate the main spreadsheet
If lastDataCell Is Nothing Then
MsgBox "The variable is blank."
Else
MsgBox lastDataCell.Row
End If
検索が失敗している場所を特定するのを手伝ってください。
前もって感謝します
このようなものはより堅牢なはずです:
Set wbConsolidator = Workbooks("Consolidator.xlsm")
Set wbQ1Actuals = Workbooks("(the spreadsheet title")
tabName = "someUserName"
If wsExist Then
With wbQ1Actuals.Worksheets(tabName)
'all range references are fully-qualified...
Set searchRange = .Range("A1", .Cells(.Rows.Count, 1).End(xlUp))
End With
Set firstDataCell = searchRange.Find("Pay Date", LookIn:=xlValues, lookat:=xlWhole)
Set lastDataCell = searchRange.Find("Total:", LookIn:=xlValues, lookat:=xlWhole)
Else
notIn414 = notIn414 & lastName & "," & firstName & ":"
End If
If lastDataCell Is Nothing Then
MsgBox "The variable is blank."
Else
MsgBox lastDataCell.Row
End If
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加