根据用户表单文本框的值隐藏行

我有一个带有两个文本框的用户表单…文本框允许用户input“from”和“to”的值。 我想隐藏“AH”列中的单元格值大于或等于“from”值且小于或等于“to”值的所有行。

我尝试了以下,但是,我没有隐藏的行?

Sub Worksheet_Calculate() Dim LastRow As Long, c As Range LastRow = Cells(Cells.Rows.Count, "AH").End(xlUp).Row For Each c In Range("AH3:AH1000") If (c.Value >= UserForm1.TextBox1.Value And c.Value <= UserForm1.TextBox2.Value) Then c.EntireRow.Hidden = False End If Next End Sub 

有任何想法吗?

谢谢

我添加了一个其他代码…这工作正常提供我声明来自和值(如下)。 但是,我无法引用我的文本框中的值。 当我尝试使用下面的行UserForm1.TextBox1.ValueUserForm1.TextBox2.Value的引用代码运行,但什么都不做?

 Sub Worksheet_Calculate() Dim LastRow As Long, c As Range LastRow = Cells(Cells.Rows.Count, "AH").End(xlUp).Row For Each c In Range("AH3:AH1000") If (c.Value >= 0 And c.Value <= 1500) Then '(c.Value > UserForm1.TextBox1.Value And c.Value < UserForm1.TextBox2.Value) Then c.EntireRow.Hidden = False Else: c.EntireRow.Hidden = True End If Next End Sub 

你会踢自己…改变

 c.EntireRow.Hidden = False 

 c.EntireRow.Hidden = True