首页 > 解决方案 > Excel VBA Math just not adding up

问题描述

I have a line of code that's working perfectly and getting what I want but I'm a little confused as to how it's doing it??

MyStr = "MANUFACTURER: LIEBHERR"

Here's the code and the result:

?VBA.Right(MyStr, VBA.Len(MyStr) - Application.Find(":", MyStr)-1) = LIEBHERR

Perfect !!!!!!

So here's my question.

?VBA.Len(MyStr) = 22

?Application.Find(":", MyStr)-1 = 12

So combining the two statements above and using the VBA.Right command when I subtract 12 from 22 it looks to me that I should get 10 but.......

?VBA.Len(MyStr) - Application.Find(":", MyStr)-1 = 8

Again, I'm getting what I want but I'm confused as to what I'm missing in my math???

标签: excelvba

解决方案


它是正确的,问题是你不能自己做Application.Find(":", MyStr)-1

VBA.Len(MyStr) - Application.Find(":", MyStr)-1

= 22 - 13 -1

= 9 - 1

= 8

你错误地认为它是:

= 22 - ( 13 - 1 )


推荐阅读