寻找不同格式的长片

时间:2016-01-20 16:57:09

标签: excel vba excel-vba

我有多种格式的数据,我正在努力改变它们以试图找到它们。有问题的数字目前以格式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

4 个答案:

答案 0 :(得分: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

答案 1 :(得分: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

答案 2 :(得分: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 :(得分:-3)

我不是100%肯定,我现在无法测试任何地方,但会

  

范围(" F2")。Value2 * 100

在这里工作?它应该给出底层值而不格式化,不是吗?