本帖最后由 jiangdifeng 于 2017-2-20 23:13 编辑
菜鸟第一次来回答下。思路是判断id号是否为空值,然后建立新的工作薄,然后判断是否存在对应的工作表,没有的新建一个,有的话直接activate,然后写入数值。其中查找是否存在工作表的步骤比较傻。先凑活下。 我自己这里运行啦,可以用。你拿去试一试看。
Sub xuqiu1()
Dim cellrange As Range Dim singlecell As Range Dim company As String Dim i As Integer Dim k As Integer Dim total As Integer
total = 0
ThisWorkbook.Activate Worksheets("sheet1").Activate Set cellrange = Range("b2", Range("b4000").End(xlUp))
Workbooks.Add
For Each singlecell In cellrange If singlecell.Value <> "" Then
company = singlecell.Offset(0, -1).Value For i = 1 To Worksheets.Count If Worksheets(i).Name <> company Then k = 0 total = k + total Else k = 1 total = k + total
End If Next i If total <> 0 Then Debug.Print company Worksheets(company).Activate Else Worksheets.Add ActiveSheet.Name = company Range("a1").Value = "company" Range("b1").Value = "number" Range("c1").Value = "time" Range("a2").Select End If total = 0 ActiveCell.Value = singlecell.Offset(0, -1).Value ActiveCell.Offset(0, 1).Value = singlecell.Value ActiveCell.Offset(0, 2).Value = singlecell.Offset(0, 1).Value ActiveCell.Offset(1, 0).Select
End If
Next singlecell End Sub
|