excel vba范围单元格错误对象定义

时间:2018-05-07 22:23:46

标签: vba excel-vba excel

我一直在研究Excel中的一个宏,它在一个表格中对表格进行排序(“次要”),当满足条件时,它应该将该表中的数据添加到第二个表格中的另一个表格中(“Sheet1” ),但我继续运行1004错误“对象未定义”,我不明白为什么,请帮助。谢谢!

Sub ord_esp_aprob()
  a = Worksheets("Minor").Cells(Rows.Count, 1).End(xlUp).Row
  b = Worksheets("Sheet1").Cells(Rows.Count, 4).End(xlUp).Row + 1

  For i = 3 To a
    If Worksheets("Minor").Cells(i, 1).Value = "Orden en Espera de Aprobación" Then
      Worksheets("Sheet1").Range(Cells(b, 4)).Value = Worksheets("Minor").Range(Cells(i, 2)).Value '(This is where the error occurs)
      Worksheets("Sheet1").Activate
    End If
  Next i
End Sub

1 个答案:

答案 0 :(得分:0)

设置值

时,您缺少范围参考
Option Explicit

Sub ord_esp_aprob()

Dim a As Long
Dim b As Long
Dim i As Long

Dim sht_minor As Worksheet
Dim sht_sht1 As Worksheet

Set sht_minor = ThisWorkbook.Worksheets("Minor")
Set sht_sht1 = ThisWorkbook.Worksheets("Sheet1")

a = sht_minor.Cells(sht_minor.Rows.Count, 1).End(xlUp).Row
b = sht_sht1.Cells(sht_sht1.Rows.Count, 4).End(xlUp).Row + 1

For i = 3 To a

If sht_minor.Cells(i, 1).Value = "Orden en Espera de Aprobación" Then
    sht_sht1.Cells(b, 4).Value = sht_minor.Cells(i, 2).Value
    sht_sht1.Activate
End If

Next i

End Sub

试试这个:

IN_FOLDER=period_to_import

cd $IN_FOLDER


for filename in *; do
WC=$(wc -w $filename)

if [ $WC -gt 33 ]
then
        rm $filename
fi
done