我对这个问题感到头疼。 我想复制细胞G4& I4(主要表)到单元格C7&另一张表格的H7(最后可用的行)。我遇到的问题是需要粘贴数据的工作表是以主工作表中Cell R4的值命名的。如果主表格单元格Q4的值为真,则仅复制数据(通过活动x控件设置) 谢谢你的帮助
答案 0 :(得分:0)
使用它:
Sub main()
Dim intCountRows As Integer
If Range("Q4") = True Then
intCountRows = GetCount(3, Worksheets(Range("R4")))
Worksheets(Range("R4")).Cells(intCountRows, 3) = Range("G4")
intCountRows = GetCount(8, Worksheets(Range("R4")))
Worksheets(Range("R4")).Cells(intCountRows, 8) = Range("I4")
End If
End Sub
Function GetCount(ByVal intColumn As Integer, ByRef wrkSheet As Worksheet) As Integer
Dim i As Integer
Dim flag As Boolean
i = 1
flag = True
While flag = True
If wrkSheet.Cells(i, intColumn) <> "" Then
i = i + 1
Else
flag = False
End If
Wend
GetCount = i - 1
End Function
我也在博客中写了一篇关于working with worksheets的文章