2

私は初心者です。私は10枚のシート、6人の従業員の名前にちなんで名付けられた6枚のシート、次の3枚の情報(私のコードとは関係ありません)、およびTempという名前の10枚目のシートを含むExcelファイルを持っています。

従業員シートには、各列に次のデータがあります (D&E は空白です)。

| A         | B                | C | D | E | F                          |
| 17-Sep-13 | ProjectA         | 6 |   |   | Report updated on this day |
| 18-Sep-13 | CBL Ideas - HMF  | 7 |   |   |                            |
| 18-Sep-13 | CBL Ideas - HMF  | 1 |   |   |                            |

次のように、Temp という名前のシートでこれらすべてのデータを照合したいと考えています。

| A         | B         | C | D   |
| 17-Sep-13 | Project A | 6 | foo |
| 18-Sep-13 | Project A | 7 | foo |
| 18-Sep-13 | Project B | 1 | foo |
| 17-Sep-13 | Project A | 6 | bar |
| 18-Sep-13 | Project A | 7 | bar |
| 18-Sep-13 | Project B | 1 | bar |

以下は私のコードです:

Sub ListRelevantEntries()
  Dim s As Integer
  Dim C As Range

  For s = 1 To Worksheets.Count - 4  
    If Sheets(s).Cells(Rows.Count, "F").End(xlUp) _
          .Value = "Report last updated on this day" Then
      'Execution stops on the below line with an
      ' "Application-defined or object defined error"
      Sheets(s).Range(Cells(Rows.Count, "F").End(xlUp) _
          .Offset(1, 0), Cells(Rows.Count, _ "A").End(xlUp)) _
          .Copy(Sheets("Temp").Cells(Rows.Count, "A").End(xlUp).Offset(1, 0))

      Sheets("Temp").Select
      Sheets("Temp").Cells(Rows.Count, "C").End(xlUp).Offset(0, 1).Select
      For Each C In Sheets("Temp").Range(Cells(Rows.Count,"C").End(xlUp). _
        Offset(0, 1), Cells(Rows.Count, "A").End(xlUp).Offset(1, 0)).Cells
        C = Sheets(s).Name
      Next
    ElseIf Not Sheets(s).Cells(Rows.Count, "F").End(xlUp) _
          .Value = "Report last updated on this day" _
          And Not Sheets(s).Cells(Rows.Count, "F").End(xlUp).Value = "" Then
  MsgBox "Extra Words entered " & ActiveSheet.Cells(Rows.Count, "F") _
      .End(xlUp).Offset(1, 0).Value & " in " & Sheets(s).Name
    End If
  Next

  Sheets("Temp").Range("1:1").Delete  
End Sub

長い質問で申し訳ありません。他に説明する方法が思いつきませんでした!

4

3 に答える 3

0

次のようなものに置き換えます

With Sheets(s)
        .Range(.Cells(.Rows.Count, "F").End(xlUp).Offset(1, 0), .Cells(.Rows.Count, "A").End(xlUp)).Copy Sheets("Temp").Cells(Sheets("Temp").Rows.Count, "A").End(xlUp).Offset(1, 0)
End With
于 2013-11-13T06:57:17.083 に答える
0

シートへの参照を返さなかったため、エラーが発生しました。簡単な修正はこれを追加することです:

Sheets(s).Select

行 6 の前または行 4 の後。

しかし、より良いコーディングのために、This Threadに見られるものを使用してみてください。
そのリンクでは、すべてのオブジェクトを宣言して設定することにより、選択の使用を回避する方法について説明しています。

于 2013-11-13T06:59:32.177 に答える