2016-11-01 358 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

这是一个很好的建议!第二部分正在做我想要的东西。 非常感谢你! –