|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
有一个多条件判断语句,目的是为了在B列填入名字后,在同行的其他列能出现对应的内容
现在这个程序跑起来特别卡,要怎么优化呢?
Private Sub Worksheet_Change(ByVal Target As Range)
Dim RR As Integer
If Target.Row < 2 Or Target.Columns.Count > 1 Or Target.Rows.Count > 1 Or Target.Column > 14 Then Exit Sub
RR = Target.Row
Select Case Target.Value
Case "Kevin"
Range("A" & RR) = Format(Now, "YYYY-MM-DD")
Range("C" & RR) = "CC"
Range("D" & RR).FormulaR1C1 = "=IFS(RIGHT(RC[1],2)=""CA"",""CA"",RIGHT(RC[1],2)=""IT"",""IT"",RIGHT(RC[1],2)=""DE"",""DE"",RIGHT(RC[1],2)=""UK"",""UK"",TRUE,""US"")"
Range("F" & RR) = "未知"
Range("G" & RR) = "未知"
Range("H" & RR).FormulaR1C1 = "=IFNA(VLOOKUP(RC[-3],VL!C[-5]:C[-4],2,0),"""")"
Range("J" & RR).FormulaR1C1 = "=IFERROR(RC[-2]*RC[-1],"""")"
Range("K" & RR) = "未知"
Range("M" & RR).FormulaR1C1 = "=10-WEEKDAY(RC[-1],2)+RC[-1]"
Case "Elisa", "Carl", "Nikki"
Target.Offset(0, 1) = "KT"
Target.Offset(0, 2) = "US"
Target.Offset(0, -1) = Format(Now, "YYYY-MM-DD")
Target.Offset(0, 6).FormulaR1C1 = "=IFNA(VLOOKUP(RC[-3],VL!C[-5]:C[-4],2,0),"""")"
Target.Offset(0, 8).FormulaR1C1 = "=IFERROR(RC[-2]*RC[-1],"""")"
Target.Offset(0, 11).FormulaR1C1 = "=10-WEEKDAY(RC[-1],2)+RC[-1]"
Case "Kelly"
Target.Offset(0, 1) = "OL"
Target.Offset(0, 2) = "US"
Target.Offset(0, -1) = Format(Now, "YYYY-MM-DD")
Target.Offset(0, 6).FormulaR1C1 = "=IFNA(VLOOKUP(RC[-3],VL!C[-5]:C[-4],2,0),"""")"
Target.Offset(0, 8).FormulaR1C1 = "=IFERROR(RC[-2]*RC[-1],"""")"
Target.Offset(0, 11).FormulaR1C1 = "=10-WEEKDAY(RC[-1],2)+RC[-1]"
Case "Jasmine"
Target.Offset(0, 1) = "KT"
Target.Offset(0, 2) = "CA"
Target.Offset(0, -1) = Format(Now, "YYYY-MM-DD")
Target.Offset(0, 6).FormulaR1C1 = "=IFNA(VLOOKUP(RC[-3],VL!C[-5]:C[-4],2,0),"""")"
Target.Offset(0, 8).FormulaR1C1 = "=IFERROR(RC[-2]*RC[-1],"""")"
Target.Offset(0, 11).FormulaR1C1 = "=10-WEEKDAY(RC[-1],2)+RC[-1]"
Case "Allen"
Target.Offset(0, 1) = "GN"
Target.Offset(0, 2) = "US"
Target.Offset(0, -1) = Format(Now, "YYYY-MM-DD")
Target.Offset(0, 6).FormulaR1C1 = "=IFNA(VLOOKUP(RC[-3],VL!C[-5]:C[-4],2,0),"""")"
Target.Offset(0, 8).FormulaR1C1 = "=IFERROR(RC[-2]*RC[-1],"""")"
Target.Offset(0, 11).FormulaR1C1 = "=10-WEEKDAY(RC[-1],2)+RC[-1]"
Case "Joy"
Target.Offset(0, 1) = "KT"
Target.Offset(0, 2).FormulaR1C1 = _
"=IFS(RIGHT(RC[1],2)=""CA"",""CA"",RIGHT(RC[1],2)=""IT"",""IT"",RIGHT(RC[1],2)=""DE"",""DE"",RIGHT(RC[1],2)=""UK"",""UK"",TRUE,""US"")"
Target.Offset(0, -1) = Format(Now, "YYYY-MM-DD")
Target.Offset(0, 6).FormulaR1C1 = "=IFNA(VLOOKUP(RC[-3],VL!C[-5]:C[-4],2,0),"""")"
Target.Offset(0, 8).FormulaR1C1 = "=IFERROR(RC[-2]*RC[-1],"""")"
Target.Offset(0, 11).FormulaR1C1 = "=10-WEEKDAY(RC[-1],2)+RC[-1]"
End Select
End Sub
运营发货需求表.rar
(203.53 KB, 下载次数: 8)
|
|