更改列顺序?

时间:2013-05-01 18:13:32

标签: vba excel-vba excel

我在IRow = ...

行上一直收到“类型不匹配”错误13

我想知道如何修复此代码?

我也是

最好的问候。

Sub MoveColumns()

Dim iRow As Long
Dim iCol As Long
Dim data_sheet1 As Worksheet
Dim target_Sheet As Worksheet

Worksheets.Add.Name = "Final Report"
Set data_sheet1 = ActiveWorkbook.Worksheets("InputPrep")
Set target_Sheet = ActiveWorkbook.Worksheets("Final Report")

iRow = Sheets(data_sheet1).UsedRange.Rows.Count
'Determine how many rows are in use

1 个答案:

答案 0 :(得分:0)

更改

iRow = Sheets(data_sheet1).UsedRange.Rows.Count

iRow = data_sheet1.UsedRange.Rows.Count

Sheets(index)期望index是工作表名称或索引编号。但是您传递的是Worksheet类型的对象。由于您已经创建了对工作表的引用,因此只需使用它。