2014-03-03 115 views
0

我对此感到满意。 我想复制单元格G4 & I4(主表单)到单元格C7 & H7的另一个表单(最后一个可用行)。我的问题是数据需要粘贴到的表单以主表单元格R4的值命名。该数据是唯一的副本,如果主表单元格Q4的值是true(设置到Active X控件) 感谢您的帮助将特定单元格复制到另一个工作表

+0

'cell C7&H7' or'Last Available Row'? –

回答

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我的博客

+0

谢谢你,但我怎样才能确保粘贴数据在最后一个aval行? – Fly

+0

好的,在那里添加了一些代码 – Pedrumj

相关问题