[英]Excel formula help
I have a excel sheet with 2 columns 我有一个有2列的excel表
Contact Status Max Probability
80-Opp Closed Won
0-NC Closed Won
40-Pending 30-Connect
10-Working 20- Engagement
80-Opportunity 30-Connect
40-Pending 10- Engagement
I need to check if the no in contact status ie the numeric value before '-' is less than numeric value in max probabilty before '-', then i need the whole value of max probability update the contact status field 我需要检查联系状态是否为' - '之前的数值是否小于' - '之前的最大概率中的数值,那么我需要最大概率的整个值更新联系状态字段
For eg. 例如。
10-Working 20- Engagement
10-Working should be replaced by 20- Engagement 10-工作应该由20-参与取代
OR 要么
We can have 20- Engagement in a new column if the above mentioned conditioned is satisfied, if replacing the contact Status column is difficult How can achieve this? 如果满足上述条件,我们可以在新列中进行20-参与,如果更换联系状态列很困难怎么能实现这一点?
This little macro will do the trick. 这个小宏将成功。 Just change
Row
to the starting row and ColA/B
to the two columns you want to use. 只需将
Row
更改为起始行,将ColA/B
更改为要使用的两列。
Note that GetNum
returns -1
if there is no number at the start which, in this implementation, means no copying. 请注意,如果开头没有数字,
GetNum
将返回-1
,在此实现中,这意味着不进行复制。 It was unclear what you wanted to do tith Closed Won
so I chose the safest option. 目前还不清楚你想要做什么tith
Closed Won
所以我选择了最安全的选择。 If you do want it copied, just return a huge number instead of -1
. 如果你想复制它,只需返回一个巨大的数字而不是
-1
。
Option Explicit
Function GetNum(s As String) As Integer
If Mid(s, 1, 1) < "0" Or Mid(s, 1, 1) > "9" Then
GetNum = -1
Else
GetNum = Val(s)
End If
End Function
Sub Macro1()
Dim Row As String
Dim ColA As String
Dim ColB As String
ColA = "A"
ColB = "B"
Row = "2"
While Range(ColA & Row).Value <> ""
If GetNum(Range(ColA & Row).Value) < GetNum(Range(ColB & Row).Value) Then
Range(ColA & Row).Value = Range(ColB & Row).Value
End If
Row = CStr(Val(Row) + 1)
Wend
End Sub
This was tested on: 这是在以下测试:
to generate: 生成:
This macro will do: 这个宏会做:
Sub a()
ColumnContSt=1
ColumnMaxProb=2
i = 1
While (Cells(i, 2) <> "")
colB = Cells(i, ColumnMaxProb)
colA = Cells(i, ColumnContSt)
posB = InStr(1, colB, "-")
posA = InStr(1, colA, "-")
If (posB <> 0 And posA <> 0) Then
intColB = CInt(Mid(colB, 1, posB - 1))
intColA = CInt(Mid(colA, 1, posA - 1))
If (intColA < intColB) Then
Cells(i, 1) = Cells(i, 2)
End If
End If
i = i + 1
Wend
End Sub
Just change ColumnContSt = 1 and ColumnMaxProb = 2 for your actual column
NUMBERS ie.
只需将ColumnContSt = 1和ColumnMaxProb = 2更改为实际列
NUMBERS即ie。 A=1, B=2, etc.
A = 1,B = 2等
HTH! HTH!
If you are flexible about the actual data, the easiest way to do this is to make two columns (can be hidden in some far away sheet): 如果您对实际数据很灵活,最简单的方法是制作两列(可以隐藏在一些远处的工作表中):
0 NC
10 Engagement
30 Connect
...
And then use VLOOKUP(CELL_WITH_PROBABILITY, REGION_WITH_TABLE, 2, true)
. 然后使用
VLOOKUP(CELL_WITH_PROBABILITY, REGION_WITH_TABLE, 2, true)
。 So if you put my small 3 element table in the upper corner of a sheet and probability in C1, it'd look like VLOOKUP(A1:B3, C1, 2, true)
因此,如果你将我的小3元素表放在一个工作表的上角和C1中的概率,它看起来像
VLOOKUP(A1:B3, C1, 2, true)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.