Search code examples
excelcellvba

Reference part of a cell in excel vba


I wanted to know a way to reference part of a value in a cell in Excel in VBA. For instance if in cell A32 I have stored 4200 cc. I would like to reference only the 4200 for calculations in a macro in VBA. So like one can reference strings or lists in python with indices, I'd like to be able to do the same. Thank you!


Solution

  • Something like this(?):

    Dim tmpArr
        tmpArr = Split(Range("A32"), " ")
    
    'any calculation in vba in this way:
    Range("B32") = tmpArr(0) / 100
    'results with 42 in cell B32
    

    EDIT If there is any doubt about recognition of number for first part of the split results you could make additional conversion in this way:

    'conversion to Double type
    Range("B32") = CDbl(tmpArr(0))/100