方法'范围'对象' _Worksheet'无法引用另一个工作表

时间:2017-05-07 19:23:37

标签: vba

这是我的代码:

Sub showUnique()

Dim VAriable As String
Dim irange As Range
Dim car As Integer
Dim Source As Worksheet
Dim Target As Worksheet
Dim inew As Range

Set Source = ActiveSheet

Range("f2").Activate 'starting point

Do
    If ActiveCell.Value <> ActiveCell.Offset(1, 0).Value Then
        VAriable = ActiveCell.Value
        Set irange = Range("f1:f1000")
    car = -Application.CountIf(irange, VAriable) + 1
  Set inew = Range(ActiveCell.Offset(0, 0), ActiveCell.Offset(car, 0)).EntireRow

'inew.Select

Set Target = Worksheets.Add(after:=Sheets(Sheets.count)) ' after last sheet
Target.Name = VAriable
' 'header row
Source.Range("a1:h1").Copy Target.Range("a1")
'handle Vehicle sales
' Set Target = Worksheets.Add(after:=Source) 'after active shett

' 'copy data
Source.Range(inew).Copy Target.Range("a2")
Target.Range("a1").CurrentRegion.Columns.AutoFit
writeKPI
    End If
    Sheets("Sales").Activate
    ActiveCell.Offset(1, 0).Activate
Loop Until IsEmpty(ActiveCell)

End Sub

获取错误&#34;方法&#39;范围&#39;对象&#39; _Worksheet&#39;失败&#34;在代码行上

Source.Range(inew).Copy Target.Range("a2")

我正在尝试在不同的工作表上引用范围并将该数据复制到新工作表

0 个答案:

没有答案