2014-05-23 85 views
0

我正在使用以下宏在工作表之間複製行值。要複製的單元格從列「C」和行「4」開始。在列「C3」上列出了標題名稱。這個值不能被複制到我的目標單元格中​​。當在「C4」中輸入值時,下面的代碼工作正常。當我將單元格「C4」留空並運行我的宏時,C3中的標題名稱正被複制到我的目標單元格中​​。在下面的示例中,我的目標列和行是「F4」。工作表之間的Excel複製行

請幫我一把。 宏代碼:

Sub Process_Copy() 

Dim row_start, row_end As Long 
Dim col_start, col_end As String 
Dim col_target, row_target As String 
Dim ws_src, ws_target As String 

col_start = "C" 
col_end = "C" 
row_start = 4 
ws_src = "Sheet1" 
ws_target = "Sheet2" 
col_target = "F" 
row_target = "4" 
row_end = Worksheets(ws_src).Range(col_start & Rows.Count).End(xlUp).Row ' to find last line 
Worksheets(ws_src).Range(col_start & row_start & ":" & col_end & row_end).Copy 
Worksheets(ws_target).Range(col_target & row_target).PasteSpecial xlPasteValues 

End Sub 

感謝。

回答

0
row_end = Worksheets(ws_src).Range(col_start & Rows.Count).End(xlUp).Row ' to find last line 

If row_end> = row_start Then 
    Worksheets(ws_src).Range(col_start & row_start & ":" & col_end & row_end).Copy 
    Worksheets(ws_target).Range(col_target & row_target).PasteSpecial xlPasteValues 
End If 
相關問題