2015-04-01 88 views
0
colname = Split(Cells(, i).Address, "$")(1) 
Lastrow = .Cells(.Rows.Count, colname).End(xlUp).Row 
ws.("?" & Lastrow).Copy ws1.Cells(Rows.Count, "A").End(xlUp).Offset(1, 0) 

i是一個數字,它被轉換爲列名。我需要一個範圍從數字4開始,例如,如果我= 1,我需要範圍(「A4」&拉斯特羅)。我有LASTROW,我可以得到A,但我怎麼讓它A4寫作範圍在excel中。

+1

'範圍( 「A4」 與LASTROW)'你的意思是'範圍( 「A4:A」 &LASTROW)' – 2015-04-01 16:20:05

回答

1
Dim ws as Worksheet 
Dim Row as integer 
Dim Col as integer 
Row = 4 
Col = 1 
Range(Cells(Row, Col), cells(LastRow, Col)) 
ws.Range(Cells(Row, Col), Cells(LastRow, Col)) 
+0

WS。 Range(Cells(4,i)&Lastrow).Copy ws1.Cells(Rows.Count,「A」)。End(xlUp).Offset(1,0)。這不起作用 – Jain 2015-04-01 16:25:02

+0

不,不會期望它。這也不是我在我的答案中提出的。如果你打算以這種方式使用它,你需要Range(** Cells **(),** Cells **())。您需要使用每個參數的'Cells()'引用來指定範圍的左上角和右下角。在那裏處理'&Lastrow'可能會引發錯誤。 – FreeMan 2015-04-01 16:28:43

+0

對不起,但我還有一件事要問。爲什麼使用這個fromat的ws.Range在沒有工作的情況下不工作,意味着它認爲活動工作表。 – Jain 2015-04-01 18:08:25