I over my head on this one. I want to copy cell G4 & I4 (main Sheet) to cell C7 & H7 of another sheet (Last available row). The problem that I have is the sheet that the data needs to be pasted to is named after the value of Cell R4 in the main sheet. The data is only copy if the value of Main sheet Cell Q4 is true (set thru active x control) Thanks for your help
use this:
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
Also i have written an article about working with worksheets in my blog
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.