寻找不同格式的多头

我有多种格式的数据,我努力改变它们,试图find它们。 有问题的数字当前以dataT.Range("F2:F" & lRow).NumberFormat = "###.00"格式存储为数字dataT.Range("F2:F" & lRow).NumberFormat = "###.00"但是,它们被存储在另一个电子表格中的其他地方,如####不包括在内。 这样的例子将是原始格式:“30.00”新格式“3000”或原始格式:“10.50”新格式“1050”。 我试图通过Replace()函数删除小数,但我相当肯定它会失败,它确实。 任何想法或build议将不胜感激。 这个function是一个更大程序中的一小部分。

提出的问题简单地说:我需要将以这种格式“30.00”存储的数字更改为目标格式“3000”。向右开始的行是我试图解决问题的地方

 Function AnalyzeOiData(lRow As Integer, oiDataSheet As Worksheet, productSheet As Worksheet, rownum As Integer) Dim counter As Integer Dim monthExp As String Dim oiLocationFinder As Range Dim strikeLoc As Range Dim optStrike As Long For counter = rownum To lRow 'Returns formatted monthcode for finding the different months of expiry embedded in the OI data monthExp = GetMonthCode(productSheet.Cells(counter, 1), productSheet.Cells(counter, 2)) optStrike = Replace(productSheet.Cells(counter, 3), ".", "") *** oiLocationFinder = oiDataSheet.Columns(1).Find(monthExp) oiLocationFinder.Select strikeLoc = Range(Selection, Selection.End(xlDown)).Find(optStrike).Address productSheet.Cells(counter, 11) = strikeLoc.Offset(0, 9) productSheet.Cells(counter, 12) = strikeLoc.Offset(0, 10) Next End Function 

将您正在处理的每个单元格input到以下子文件中:

 Sub Convert(cell As Range) If cell.NumberFormat = "0.00" Then cell.Value = cell.Value * 100 cell.NumberFormat = "0" End If End Sub 

如果你喂这些细胞在…

原始数据

结果是:

处理的数据

您可以使用Find运行高效的search,而不是查看每个单元格:

 Dim rng1 As Range Application.FindFormat.NumberFormat = "0.00" Set rng1 = Range("A1:A10").Find("*", , , , , , , , True) Do While Not rng1 Is Nothing rng1.Value2 = rng1.Value2 * 100 rng1.NumberFormat = "0" Set rng1 = Range("A1:A10").Find("*", , , , , , , , True) Loop 

为了将“乘以100”的答案扩大到更一般的东西,下面的代码将查看有多less小数位,然后乘以正确的因子10去除小数。

 Dim iDec as Integer If Instr(1,productSheet.Cells(counter,3),".") > 0 Then iDec = Len(productSheet.Cells(counter,3))-Application.WorksheetFunction.Find(".",productSheet.Cells(counter,3)) productSheet.Cells(counter,3) = productSheet.Cells(counter,3) * (10^iDec) End If 

我不是100%肯定的,现在我不能testing任何地方,但会

范围(“F2”),值2 * 100

在这里工作? 它应该给没有格式的基础价值,没有?