(Solved) – How can I type a Formula in a textbox and get it calculated (VBA)?

  • by

I would like to calculate something with the given columns in an excel sheet

enter image description here

'Find las column in the excel sheet "lstColumn is the variable in the sub procedure FindeLetzteSpalte"
    Call FindeLetzteSpalte
    'Find last row in the excel sheet "lstRow is the variable in the sub procedure FindeLetzteZeile"
    Call FindeLetzteZeile

    Dim KanalNamenArray() As String
    Dim cKN As Integer

    'Write all channels ("Time Axis" to "Channel F") in an Array
    ReDim KanalNamenArray(1 To lstColumn)
    For cKN = 1 To lstColumn
        KanalNamenArray(cKN) = Cells(1, cKN)
    Next cKN

    'cKN gives me the Column-Index for each channel ("Time Axis" to "Channel F") in the sheet
    Dim sentence        As String
    Dim cntForF         As Long
    Dim cntIntern       As Long
    Dim hasWord         As Boolean
    Dim ResultFormula As Long
    Dim InputVarIndex(1 To 100) As Integer

    cntIntern = 0

    'Example sentence (Equation which I want to type in the textbox shown in the picture attached)
    sentence = "Date   Channel F"

    For cntForF = LBound(KanalNamenArray) To UBound(KanalNamenArray)
        If InStr(1, sentence, Trim(KanalNamenArray(cntForF))) Then
            hasWord = True

            'cntForF gives me the Column-Index of "Date" and "Channel F" from the variable sentence
            InputVarIndex(cntIntern) = cntForF
        End If
    Next cntForF

So I am able to find the Column-Index of the channels which are written in the sentence-variable.

The next thing would be to calculate every row of column Date and column Channel F
(like “Date Channel F”)

But I have no clue how to do that

basically what i want is to create another channel which can be calculated with the current available channels and add the new channel next to the last column.

Something like “Channel G” = “Time Axis” “Channel F”

i hope i explained well enough.

i would appreciate if anyone could give me an idea… I’m also willing to accept a complete different way of thinking

Thanks a lot

Leave a Reply

Your email address will not be published. Required fields are marked *