[英]Copy specific cell to another sheet
我對這個感到頭疼。 我要將單元格G4和I4(主工作表)復制到另一張工作表(最后可用行)的單元格C7和H7。 我遇到的問題是需要將數據粘貼到的工作表是以主工作表中的單元格R4的值命名的。 僅當主工作表單元格Q4的值為true(通過活動x控件設置)時,才復制數據。感謝您的幫助
用這個:
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
我也在博客中寫了一篇關於使用工作表的文章
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.