
excel宏中的IF编写,请高手帮忙!最佳答案送高分! 80
我编写了一个fliter的宏,想在输入某查找条件没有对应记录的时候弹出重新输入条件的对话框,应该怎么用if语句编写?就是不明白条件语句怎么编写,下面我编写的宏,就是要在最...
我编写了一个fliter的宏,想在输入某查找条件没有对应记录的时候弹出重新输入条件的对话框,应该怎么用if语句编写?
就是不明白条件语句怎么编写,下面我编写的宏,就是要在最后那个msgbox那个地方加个if
Sub SelectClient()
'
' SelectClient Macro
'
' Keyboard Shortcut: Ctrl+Shift+I
'
ActiveWindow.SmallScroll Down:=84
Range("A100").Select
ActiveCell.FormulaR1C1 = InputBox("Please enter last name.")
With ActiveCell.Characters(Start:=1, Length:=3).Font
.Name = "Arial"
.FontStyle = "Regular"
.Size = 10
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = 1
.TintAndShade = 0
.ThemeFont = xlThemeFontNone
End With
Range("C93").Select
Range("A9:I97").AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:= _
Range("A99:I100"), Unique:=False
ActiveWindow.SmallScroll Down:=-9
MsgBox ("If no clients satisfied the criteria,please rerun a macro.")
End Sub 展开
就是不明白条件语句怎么编写,下面我编写的宏,就是要在最后那个msgbox那个地方加个if
Sub SelectClient()
'
' SelectClient Macro
'
' Keyboard Shortcut: Ctrl+Shift+I
'
ActiveWindow.SmallScroll Down:=84
Range("A100").Select
ActiveCell.FormulaR1C1 = InputBox("Please enter last name.")
With ActiveCell.Characters(Start:=1, Length:=3).Font
.Name = "Arial"
.FontStyle = "Regular"
.Size = 10
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = 1
.TintAndShade = 0
.ThemeFont = xlThemeFontNone
End With
Range("C93").Select
Range("A9:I97").AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:= _
Range("A99:I100"), Unique:=False
ActiveWindow.SmallScroll Down:=-9
MsgBox ("If no clients satisfied the criteria,please rerun a macro.")
End Sub 展开
3个回答
展开全部
这个应该是你想要的结果了:
Sub SelectClient()
'
' SelectClient Macro
'
' Keyboard Shortcut: Ctrl+Shift+I
'
On Error GoTo EXIT_SUB
ActiveWindow.SmallScroll Down:=84
Range("A100").Select
ActiveCell.FormulaR1C1 = InputBox("Please enter last name.")
With ActiveCell.Characters(Start:=1, Length:=3).Font
.Name = "Arial"
.FontStyle = "Regular"
.Size = 10
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = 1
.TintAndShade = 0
.ThemeFont = xlThemeFontNone
End With
Range("C93").Select
Range("A9:I97").AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:= _
Range("A99:I100"), Unique:=False
ActiveWindow.SmallScroll Down:=-9
Exit Sub
EXIT_SUB:
MsgBox ("If no clients satisfied the criteria,please rerun a macro.")
End Sub
Sub SelectClient()
'
' SelectClient Macro
'
' Keyboard Shortcut: Ctrl+Shift+I
'
On Error GoTo EXIT_SUB
ActiveWindow.SmallScroll Down:=84
Range("A100").Select
ActiveCell.FormulaR1C1 = InputBox("Please enter last name.")
With ActiveCell.Characters(Start:=1, Length:=3).Font
.Name = "Arial"
.FontStyle = "Regular"
.Size = 10
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = 1
.TintAndShade = 0
.ThemeFont = xlThemeFontNone
End With
Range("C93").Select
Range("A9:I97").AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:= _
Range("A99:I100"), Unique:=False
ActiveWindow.SmallScroll Down:=-9
Exit Sub
EXIT_SUB:
MsgBox ("If no clients satisfied the criteria,please rerun a macro.")
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询