在新的Range / Rows定义中使用Cells.Find中的行号

时间:2018-02-05 11:29:49

标签: vba excel-vba compiler-errors range excel

我希望在一些帮助下调试这个简单的代码。

我正在尝试为工作簿中的每个工作表剪切并粘贴由特定单元格值标识的行范围

我的问题是,当我定义要剪切的范围时,我收到1004错误。

在我的代码下面:

Sub WorksheetLoop()

     Dim WS_Count As Integer
     Dim I As Integer

     ' Set WS_Count equal to the number of worksheets in the active
     ' workbook.
     WS_Count = ActiveWorkbook.Worksheets.Count

     ' Begin the loop.
     For I = 1 To WS_Count


     ' Define Range Boundaries and insert Location
    Dim Lstress As String
       Lstress = (Cells.Find(What:="Long Shear (N)", After:=Range("A1"), LookAt:=xlPart, LookIn:=xlFormulas, SearchOrder:=xlByRows, SearchDirection:=xlNext).Row) - 1
       MsgBox "Last Row:" & Lstress
    Dim Disp As String
       Disp = Cells.Find(What:="Displacement X(m)", After:=Range("A1"), LookAt:=xlPart, LookIn:=xlFormulas, SearchOrder:=xlByRows, SearchDirection:=xlNext).Row
       MsgBox "Last Row:" & Disp
    Dim Rigging As String
       Rigging = (Cells.Find(What:="Standing Rigging", After:=Range("A1"), LookAt:=xlPart, LookIn:=xlFormulas, SearchOrder:=xlByRows, SearchDirection:=xlNext).Row) - 1
       MsgBox "Last Row:" & Rigging
    Dim Cutrange As String
       Let Cutrange = "A" & Disp & ":" & "D" & Lstress

      'Cut and Paste Action
       Range("CutRange").Cut
       Rows("Rigging").Insert Shift:=xlDown

      ' The following line shows how to reference a sheet within
      ' the loop by displaying the worksheet name in a dialog box.
       MsgBox ActiveWorkbook.Worksheets(I).Name

     Next I

  End Sub

如果我尝试使用而不是Range,Rows

,则会出现同样的错误

Rows("Disp:Lstress").Cut

我认为这个问题与Cells.Find.Row的输出有关。 我的意思是mesgBox中的数值是正确的,但可能格式无法在Range / Rows中使用。

感谢您的帮助 爱德华多

0 个答案:

没有答案