vba Excel 2010 选中一行中的每个单元格,将它们一一激活
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9096636/
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
Excel 2010 select each cell in a row, activate them one by one
提问by Dante1986
I have an XML file that I drop into Excel to make it automatically generate a table. First column(A) has a name, and the second column(B) has a date. There are a few more columns, but those are not relevant to this question.
我有一个 XML 文件,我将它放入 Excel 中以使其自动生成一个表格。第一列(A)有一个名字,第二列(B)有一个日期。还有几列,但那些与这个问题无关。
So it looks like this screenshot:
所以它看起来像这个截图:
Now there is a very idiotic bug in Excel (2010). When I have the Data column, I set its property to be Dates. But Excel does not understand they are dates now. But if I double click in a cell to activate it, at that point it starts to understand its a date... strange bug, but I have to to this for each cell.
现在Excel(2010)中有一个非常愚蠢的错误。当我有数据列时,我将其属性设置为日期。但是 Excel 现在不明白它们是日期。但是如果我双击一个单元格来激活它,那么它就会开始理解它的日期......奇怪的错误,但我必须为每个单元格做这个。
Now what I was thinking, is to have some macro or something, that activates each cell (if there is content) one after another in the B column.
现在我在想的是有一些宏或其他东西,它会一个接一个地激活 B 列中的每个单元格(如果有内容)。
Now, I don't have a clue how I can do this in the build in VBA of Excel.
现在,我不知道如何在 Excel 的 VBA 中执行此操作。
Is there someone out here that could help me? I can imagine it would only need a handful of lines to make it work.
这里有人可以帮助我吗?我可以想象它只需要几行代码就可以使它工作。
采纳答案by Storm
Try this:
尝试这个:
Sub MacroTest()
Sheets("Sheet1").Select
LastRangeRow = Cells.Find("*", after:=Range("A1"), searchdirection:=xlPrevious).Row
Set Rng = Range("Sheet1!B2:B" & LastRangeRow)
For Each c In Rng.Cells
c.Select
SendKeys "{F2}", True
SendKeys "{ENTER}", True
Selection.NumberFormat = "dd/mm/yyyy hh:mm:ss"
Next
Range("A1").Select
End Sub
回答by Neil
Highlight column B / click Data / Text to Columns / select Delimited / click Finish (without a delimiter selected).
突出显示 B 列/单击数据/文本到列/选择分隔/单击完成(未选择分隔符)。
That should do it.
那应该这样做。
回答by PynkRabbit
I have experienced this before - in the Formula's Ribbon > Calculation Box > Calculation Options drop down check to make sure 'Automatic' is selected. Usually when 'Manual' is selected mass formatting changes like that wont take effect unless you manually refresh cell (i.e. select and press enter)
我以前经历过这种情况 - 在公式的功能区 > 计算框 > 计算选项下拉检查以确保选择了“自动”。Usually when 'Manual' is selected mass formatting changes like that wont take effect unless you manually refresh cell (ie select and press enter)
回答by Tim J aus M
The easiest thing ist to just run a calculation on the respective cells:
最简单的方法是对相应的单元格运行计算:
=A1-0
=A1-0
And the copy & paste the values :-)
以及复制和粘贴值:-)
回答by office
I use this:
我用这个:
Sub makeDate()
Dim rAn As Range
Application.ScreenUpdating = 0: Application.EnableEvents = 0: Application.Calculation = xlCalculationManual
For Each rAn In Selection.SpecialCells(xlCellTypeVisible)
rAn.NumberFormat = "dd/mm/yyyy"
rAn = Trim(rAn.Text)
rAn = DateValue(rAn)
Next rAn
Application.ScreenUpdating = 1: Application.EnableEvents = 1: Application.Calculation = xlCalculationAutomatic
End Sub
回答by datatoo
It appears you have AutoCorrect working for or against you. If you notice the small blue triangle in the bottom of row 20. Although smart tags were discontinued in 2010, so it may be this is not be your situation.
看来您有自动更正对您有利或不利。如果您注意到第 20 行底部的蓝色小三角形。虽然智能标签已于 2010 年停产,所以这可能不是您的情况。
This is the Offce Link regarding AutoCorrect ButtonsIn Preferences>Proofing>AutoCorrect Options>Actions you may control additional actions and whether Excel is trying to correct your date input. I don't have a sample of your data to test with, but fiddling in those preferences may get excel to not help so much.
这是关于首选项>校对>自动更正选项>操作中的自动更正按钮的Office链接,您可以控制其他操作以及Excel是否正在尝试更正您的日期输入。我没有你的数据样本来测试,但摆弄这些偏好可能会变得非常有用。