|
代码如下:
不知道自己是不是能说清楚,这段代码目的是将sheet1,sheet2,sheet3里的含有批注的单元格,将单元格的值(是数字)按从上到下的顺序赋在sheet5内,将单元格的批注也转录制sheet5的已经转录的数字单元格右边。
由于检索到的第一个单元格值为14,总共含批注的单元格是87,所以最后录了似乎是87或者88行一样的值,都是14那格,问下大神们怎么改才对,这个循环我搞不定了。谢谢大神们!!!!
'自动录入
Private Sub CommandButton4_Click()
Dim a As Integer, cs As Integer, rs As Integer, z As Integer, i As Integer, j As Integer
'含批注单元格个数
s = 0
For i = 1 To 100
For j = 1 To 100
If Sheet1.Cells(i, j).Comment Is Nothing And Sheet2.Cells(i, j).Comment Is Nothing _
And Sheet3.Cells(i, j).Comment Is Nothing Then
s = s + 0
Else
s = s + 1
End If
Next j
Next i
z = Sheet5.UsedRange.Rows.Count
For j = 1 To s
For cs = 1 To 100
For rs = 1 To 100
If Sheet1.Cells(rs, cs).Value <> "" Then
If Sheet1.Cells(rs, cs).Comment Is Nothing Then
Cells(1, 1).Select
Else
ActiveSheet.Cells(z + j, 3).Value = Sheet1.Cells(rs, cs).Value
ActiveSheet.Cells(z + j, 4).Value = Sheet1.Cells(rs, cs).Comment.Text
End If
ElseIf Sheet2.Cells(rs, cs).Value <> "" Then
If Sheet2.Cells(rs, cs).Comment Is Nothing Then
Cells(1, 1).Select
Else
ActiveSheet.Cells(z + j, 3).Value = Sheet2.Cells(rs, cs).Value
ActiveSheet.Cells(z + j, 4).Value = Sheet2.Cells(rs, cs).Comment.Text
End If
ElseIf Sheet3.Cells(rs, cs).Value <> "" Then
If Sheet3.Cells(rs, cs).Comment Is Nothing Then
Cells(1, 1).Select
Else
ActiveSheet.Cells(z + j, 3).Value = Sheet3.Cells(rs, cs).Value
ActiveSheet.Cells(z + j, 4).Value = Sheet3.Cells(rs, cs).Comment.Text
End If
End If
Next rs
Next cs
Next j
End Sub
- Private Sub CommandButton4_Click()
- Dim rngs As Range, rng As Range, arr(1 To 10000, 1 To 2), r&, sh&
- On Error Resume Next
- For sh = 2 To 4
- Set rngs = Sheets(sh).Cells.SpecialCells(xlCellTypeComments)
- If Not rngs Is Nothing Then
- For Each rng In rngs
- If rng <> "" Then
- r = r + 1
- arr(r, 1) = rng
- arr(r, 2) = rng.Comment.Text
- End If
- Next rng
- End If
- Next sh
- [c2].Resize(r, 2) = arr
- End Sub
复制代码
|
|