更改列号格式

我从一个电子表格复制列到另一个:

Set sourceColumn = wb.Worksheets(cmb).Columns(wb.Sheets(cmb).Rows(1).Find(Form.ComboBox2.Value).Column) Set targetColumn = Workbooks("B.xlsm").ActiveSheet.Columns("A") sourceColumn.Copy Destination:=targetColumn 

复制后,我想将targetColumn的数字格式转换为数字。 在这篇文章的参考文献中,我尝试了Workbooks("B.xlsm").ActiveSheet.Columns("1").NumberFormat = "0"但是不会将列格式从文本更改为数字。

任何想法什么是错误的?

如果您确定列中的所有值都是以文本forms格式化的数字,则可以尝试“ 文本到列”function,如下所示:

 With Workbooks("B.xlsm").ActiveSheet ' you might want to be more explicit here .Columns(1).TextToColumns Destination:=.Columns(1), _ DataType:=xlDelimited, _ FieldInfo:=Array(1, 1) End With 

上面将列1格式更改为常规 ,使所有条目看起来像一个数字到数字格式。