私は以下のコードを記述しましたが、何が間違っているかを検出できないようです。プログラムは、ブックからデータを転送するように設定されている:VBAコードで時々エラーが返される場合があります。
SRJem.xlsx
を以下のコードが書き込まれるアクティブブックに。今、私は両方のワークブックを同時に開いている(そして私は操作をしている間に閉じたくない)。問題は、ある時点でコードが成功しているのに対し、15行目にバグが返ってくることがあります。私は両方の操作を保存することを試みたが、それはまだ起こる。
ライン15:
ws.Cells(iRow、4).Valueの= wbSource.Sheets( "1")細胞(14、1).Valueの
Iのいくつかを必要とします。私が持っているエラーに関する軽い説明。どうもありがとうございます。
Sub transfer_to_masterfile()
'find first empty row in database
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("1")
Dim wbSource As Workbook
iRow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, _
SearchDirection:=xlPrevious, LookIn:=xlValues).row + 1
Set wbSource = Workbooks.Open("C:\Users\fed.staff01\Desktop\J.G.E - QS\6. EXCEL PROGRAMS\SRJem.xlsx") ' <<< path to source workbook
'Now, transfer values from wbSource to wbTarget:
ws.Cells(iRow, 4).Value = wbSource.Sheets("1").Cells(14, 1).Value
ws.Cells(iRow, 5).Value = wbSource.Sheets("1").Cells(6, 4).Value
Dim mats As String
Dim row As Integer
row = 23
Do
mats = mats & " " & wbSource.Sheets("1").Cells(row, 1).Value & " " & wbSource.Sheets("1").Cells(row, 3).Value & _
" " & wbSource.Sheets("1").Cells(row, 5).Value
If wbSource.Sheets("1").Cells(row + 1, 1).Value > 0 Then
mats = mats & vbNewLine
End If
If wbSource.Sheets("1").Cells(row + 1, 1).Value = "" Then
Exit Do
End If
row = row + 1
Loop Until row = 42
ws.Cells(iRow, 7).Value = mats
'ws.Cells(iRow, 5).Value = wbSource.Sheets("1").Cells(6, 4).Value
'wbSource.Close
'wbTarget.Close
End Sub
ワークシートの名前は「1」ですか?あるいは、最初の '1'を参照しようとしていますか? – PatricK
@PatricK、私は「1」のワークシート名を参照しています。 –
質問に答えを記入するには、回答の左側にある「ダニ」をクリックしてください。 [ヘルプファイル。](https://stackoverflow.com/help/accepted-answer) –