2016-01-20 58 views
2

我有多种格式的数据,并且我努力改变它们以尝试找到它们。所讨论的数字目前以dataT.Range("F2:F" & lRow).NumberFormat = "###.00"的格式存储为数字。但是,它们存储在另一个电子表格的其他地方,其格式为####,不包括小数。这样的例子将是原始格式:“30.00”新格式“3000”或原始格式:“10.50”新格式“1050”。我试图通过Replace()函数删除小数,但我相当肯定它会失败,它确实如此。任何想法或建议将不胜感激。这个功能是一个更大程序中非常小的一部分。发现不同格式的长文字

问题简单地说:我需要改变以这种格式存储“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 
+5

'10.50 * 100 = 1050'? –

+0

请修复您的文章中的代码的格式,谢谢:) – Archimaredes

+0

刚刚去做,斯科特做到了。当我复制它时,它会被抛弃。 – StormsEdge

回答

2

输入您要加工成以下子每个单元:

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

如果你给这些细胞中......

Original data

...结果是:

Processed data

0

为拓宽答案“乘以100”到更多的东西一般情况下,下面的代码会看看,看看有多少位小数有,然后乘以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 
-3

我不是100%肯定,我不任何地方,我现在就可以考,但会

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

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

+1

对于“30.00”的输入,这将按照要求给出“30”,而不是“3000”。 – nwhaught

1

您可以运行与Find高效的搜索,而不是看每个单元:

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