简体   繁体   English

在每个Excel单元格前面插入文本

[英]Insert text in front of each Excel cell

I have an Excel 2010 worksheet with a column of numbers, eg 我有一个带有一列数字的Excel 2010工作表,例如

-1.5629E+00
-1.5745E+00
-1.4344E+00
-1.6456E+00

These are log10 values, and I want the original values: 这些是log10值,我想要原始值:

0.027359
0.026638
0.036776
0.022614

Of course I could insert a column with the proper operation done, but that would upset subsequent use of the worksheet. 当然,我可以插入一个完成正确操作的列,但这会扰乱后续使用工作表。 I'd rather find a way to insert this text 我宁愿找到一种方法来插入这个文本

=10^ = 10 ^

in the beginning of each cell in the original column. 在原始列中每个单元格的开头。 I tried recording a macro, but that feature simply recording adding an entire new entry in the cell, not inserting text at the beginning. 我尝试录制一个宏,但该功能只是记录在单元格中添加一个完整的新条目,而不是在开头插入文本。

Select your log10 values and run this: 选择log10值并运行:

Sub AntiLog()
    Dim c as Range
    For Each c in Selection.Cells
        If IsNumeric(c.value) then c.Value=10^c.Value
    Next c
End Sub

I think you may have misunderstood @pnuts's comment above. 我想你可能误解了@pnuts的评论。 VBA seems like overkill here. VBA在这里似乎有些过分。 Let's say your column of values is A . 假设您的值列为A In column B , use the formula B列中,使用公式

=10^A1

and then apply that downward. 然后向下应用。 Finally, copy that column and paste special as values over column A and then delete column B . 最后,复制该列并将特殊值粘贴到列A ,然后删除列B

Here's what I finally arrived at: 这是我最终得到的:

Sub AntiLog()
Dim c As Range
For Each c In Selection.Cells
    If IsNumeric(c.Value) And Not IsEmpty(c.Value) Then c.Value = 10 ^ c.Value
Next c
End Sub

Associate with any key desired. 与任何所需的关键相关联。 Then, click on the entire column range, tap your key, and job done in place. 然后,单击整个列范围,点击您的键,然后完成工作。 More work initially but now it's a few-second process to fix these columns. 最初工作量很大,但现在修复这些列只需要几秒钟的时间。 Thanks to everybody who responded, and esp. 感谢所有回复的人,尤其是 Tim Williams; 蒂姆威廉斯; your code gave me enough to get the final job. 你的代码足以让我获得最后的工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM