2016-11-01 357 views
0

我有下面的代碼:空白單元格

Worksheets("L.NAM.M").Select 
    Cells.Select 
    Selection.Find(What:="forecast_quarter", After:=ActiveCell, LookIn:= _ 
     xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _ 
     xlNext, MatchCase:=False, SearchFormat:=False).Activate 
    **Range("A2").Select 
    Range(Selection, Selection.End(xlDown)).Select** 
    Selection.Copy 
    Sheets("NewForecast").Select 
    Range("K" & Rows.Count).End(xlUp).Offset(1).Select 
    ActiveSheet.Paste 
的禿線,我想找到最後一行數據

,但如果我有空白單元格在中間,它將不會複製空白單元格之後的內容。我想複製一切,甚至是空白單元格。有數據 所以如果在範圍A2:A100,A41是空白的,我希望它繼續下去,直到最後的數據,然後複製一切,甚至是A41。 任何想法?

回答

0

這裏是你的代碼的小改版,堅持其實際作用並請求:

Worksheets("L.NAM.M").Select 
Cells.Find(What:="forecast_quarter", After:=ActiveCell, LookIn:= _ 
    xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _ 
    xlNext, MatchCase:=False, SearchFormat:=False).Activate 
Range("A2", Cells(Rows.Count, "A").End(xlUp)).Copy 
Sheets("NewForecast").Range("K" & Rows.Count).End(xlUp).Offset(1).PasteSpecial 

  • 發現「forecast_quarter」沒有用的,似乎,因爲你不根本不使用那個單元格

  • 仍然有一些應該避免的選擇/激活

    這可以,只要做你介紹一下前點


編輯後你可能會真正想要做的一些想法

應該你曾經想:

  • 將「L.NAM.M」工作表中的單元格從「forecast_quarter」下面的那個開始複製到最後一個不爲空一個在同一列

  • 其粘貼到第一不空單元格列「K」工作表的「NewForecast」

那就試試這個:

Sub main() 
    With Worksheets("L.NAM.M") 
     With .Cells.Find(What:="forecast_quarter", After:=ActiveCell, LookIn:= _ 
      xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _ 
      xlNext, MatchCase:=False, SearchFormat:=False) 
      .Parent.Range(.Offset(1), .Parent.Cells(Rows.Count, .Column).End(xlUp)).Copy Destination:=Worksheets("NewForecast").Range("K" & Rows.Count).End(xlUp).Offset(1) 
     End With 
    End With 
End Sub 
+0

這是一個很好的建議!第二部分正在做我想要的東西。 非常感謝你! –