Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel 使用vba代码而不是循环更改列的值_Excel_Vba - Fatal编程技术网

Excel 使用vba代码而不是循环更改列的值

Excel 使用vba代码而不是循环更改列的值,excel,vba,Excel,Vba,我想在一列中的每个单元格(超过13000个单元格)之前添加“#”,并通过vba excel代码将“000”添加到另一列。我可以通过循环实现这一点,但运行宏时需要很长时间。谁能帮我找到更有效的解决方案 for each cell in column cell = "#"& cell next cell for each cell in column select case len(cell) case 2: cell = "'000&

我想在一列中的每个单元格(超过13000个单元格)之前添加
“#”
,并通过vba excel代码将
“000”
添加到另一列。我可以通过循环实现这一点,但运行宏时需要很长时间。谁能帮我找到更有效的解决方案

for each cell in column
  cell = "#"& cell
  next cell

for each cell in column
   select case len(cell)
     case 2: cell = "'000" & cell
     case 3: cell = "'00" & cell
   end select
    
next cell
预期结果:

456=>456

10=>00010

但是它运行非常慢。

使用显示格式:

Range("A1:A1300").NumberFormat = "\##"
Range("B1:B1300").NumberFormat = "00000"
这不会更改基础值,但会正确显示

要读取值,请使用Cell.Text检索带前导零的字符串。

使用显示格式:

Range("A1:A1300").NumberFormat = "\##"
Range("B1:B1300").NumberFormat = "00000"
这不会更改基础值,但会正确显示


要读取值,请使用Cell.Text检索带前导零的字符串。

Hi Storm。我已经测试过了,但Cell.Text似乎只有在通过msgbox打印时才起作用。我无法分配或更改实际值。例如:射程(“c1”)=射程(“a1”)。text风暴。我已经测试过了,但Cell.Text似乎只有在通过msgbox打印时才起作用。我无法分配或更改实际值。例如:范围(“c1”)=范围(“a1”)。文本