vba 从 ActiveCell 中选择列中的第一个单元格。列中的数据包括空格

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25450321/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-12 04:21:44  来源:igfitidea点击:

Select from ActiveCell to first cell in column. Data in column includes blanks

excelvba

提问by Devin McGhee

I have a sheet with data that contains no blanks in the first column. Subsequent columns contain blanks. I need to set individual columns to several range variables. The problem I am having is that using "xlUp" stops at the first blank.

我有一张数据表,第一列中没有空格。后续列包含空白。我需要将各个列设置为多个范围变量。我遇到的问题是使用“xlUp”在第一个空白处停止。

Any suggestions on what to do?

关于该怎么做的任何建议?

Here is some example code. I'm commenting out the lines that I have been using to try and get this to work (the copy line was so I could paste into a blank sheet to see what was being selected.)

这是一些示例代码。我正在注释掉我一直用来尝试使其工作的行(复制行是为了我可以粘贴到一张空白表中以查看被选择的内容。)

Sub Test_Subject_Ranges()
    Sheets("Current Day Raw").Select
    ActiveSheet.Range("A1").Select    
    Range("A1").End(xlDown).Select                 'Takes me to the bottom of my data.
    ActiveCell.Offset(0, 11).Select                'Takes me to the column I need here.
==> Range(ActiveCell, ActiveCell.End(xlUp)).Select 'The problem line.
    Dim CurrentDayPALessonsPassed As Range
    Set CurrentDayPALessonsPassed = Selection
    Selection.Copy
End Sub

采纳答案by Gary's Student

This will select all cells from the ActiveCellto the top of the column in which it resides:

这将选择从ActiveCell到它所在列顶部的所有单元格:

Sub ToTheTop()
    Range(ActiveCell, ActiveCell.EntireColumn.Cells(1)).Select
End Sub