sum the two value
-
Hi, I have this code below and I want to get the sum of the amount of the "441210" and "441110". Please show me the code. thanks. Case "441210" amt = Mid(strLine, 93, [20]) Range("I10").Select Range("I10").Value = amt Case "441110" amt = Mid(strLine, 93, [20]) Range("J10").Select Range("J10").Value Range("J10").Value = amt Thanks
-
Hi, I have this code below and I want to get the sum of the amount of the "441210" and "441110". Please show me the code. thanks. Case "441210" amt = Mid(strLine, 93, [20]) Range("I10").Select Range("I10").Value = amt Case "441110" amt = Mid(strLine, 93, [20]) Range("J10").Select Range("J10").Value Range("J10").Value = amt Thanks
You're kidding, right ? Use Convert.ToInt32 to get ints, then use the + operator to add them. Your code is pretty messy, if you know the values, why are you calling Mid, or is that not what this is doing ? Christian Graus - Microsoft MVP - C++
-
Hi, I have this code below and I want to get the sum of the amount of the "441210" and "441110". Please show me the code. thanks. Case "441210" amt = Mid(strLine, 93, [20]) Range("I10").Select Range("I10").Value = amt Case "441110" amt = Mid(strLine, 93, [20]) Range("J10").Select Range("J10").Value Range("J10").Value = amt Thanks
The Case blocks are separate blocks of code - in other words the case for handling "441210" does NOT drop through to case "41110". What you'll need to do as create a separate variable to hold the sum of these cases viz:
Dim totalAmt as Integer totalAmt = 0 Select Case .... Case "441210" amt = Mid(strLine, 93, [20]) Range("I10").Select Range("I10").Value = amt totalAmt = totalAmt + amt Case "441110" amt = Mid(strLine, 93, [20]) Range("J10").Select Range("J10").Value Range("J10").Value = amt totalAmt = totalAmt + amt End Select
The variabletotalAmt
will hold the sum of the two cases and you can then use this in your program. ...Steve -
You're kidding, right ? Use Convert.ToInt32 to get ints, then use the + operator to add them. Your code is pretty messy, if you know the values, why are you calling Mid, or is that not what this is doing ? Christian Graus - Microsoft MVP - C++