不确定如何使用下面概述的步骤来完成此代码。任何帮助表示赞赏
Sub Test()
Dim Value As Double
For Each Value In ThisWorkbook.Sheets("Sheet").Range("V17:V57")
If Value.ThisWorkbook.Sheets("Sheet").Range("V17:V57") = 0 Then...
...
End If
End Sub
检查范围内是否存在0
如果为真...
其他...
使用Application.WorksheetFunction.FormulaArray ("MAX(IF(V17:V37<=0,V17:V37),MIN(V17:V37))")
找到/选中单元格一次,通过更改选中单元格左侧的4个单元格中的值,执行目标搜索以将所选单元格设置为0。
如上所述自动更新“数据验证”源范围
对于0存在的情况,我正在尝试这段代码,但是如何根据数据表另一列中的单元格的相应范围来设置验证范围? H24单元格是我的下拉列表所在的位置
Dim rng As Range
For Each rng In ThisWorkbook.Sheets("Sheet").Range("V17:V57")
If rng.Value = 0 Then
ThisWorkbook.Sheets("Sheet").Select
Range ("H24").Select
With Selection.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _ xlBetween, Formula1:="=Sheet!$V$17:$V" & ??
Else...
以下代码在评估行给出调试错误。 整体代码块需要简化...如果,对于,下一步太多?为了清楚起见,我添加了注释。目标搜索线也需要帮助。
Dim rng As Range
For Each rng In ThisWorkbook.Sheets("Sheet").Range("V17:V57")
If rng.Value <> 0 Then
rng = Application.WorksheetFunction.FormulaArray("MAX(IF(V17:V57<=0,V17:V57),MIN(V17:V57))") 'this formula searches for the least min number in the range
rng.Select
Range("selected cell").GoalSeek Goal:=0, ChangingCell:=Range("cell 5 columns left of selected cell")...this line makes selected cell = 0
Exit For
End If
Next rng
答案 0 :(得分:1)
假设您要在 A1:B10 范围内找到值“ 3 ”:
Set given_range = ThisWorkbook.Worksheets("Sheet1").Range("A1:B10")
given_range.Select
Set found_value = Selection.Find("3")
如果您要查找其地址:
value_address = found_value.Address(0,0)
最后使用(0,0)将返回没有任何 $ (B3而不是$ B $ 3)的地址
另外,:如果您想知道行或列,请执行以下操作
value_column = Split(found_value.Address, "$")(1)
value_row = Split(found_value.Address, "$")(2)
答案 1 :(得分:0)
'To check if an element is within a specific Array, Object, Range, String, etc.
Public Function isInArray(ByVal itemSearched As Variant, ByVal aArray As Variant) As Boolean
Dim item As Variant
If VarType(aArray) >= vbArray Or VarType(aArray) = vbObject Or VarType(aArray) = vbDataObject Or TypeName(aArray) = "Range" Then
For Each item In aArray
If itemSearched = item Then
isInArray = True
Exit Function
End If
Next item
isInArray = False
ElseIf VarType(aArray) = vbString Then
isInArray = InStr(1, aArray, itemSearched, vbBinaryCompare) > 0 'Comparing character by character
Else
On Error Resume Next
isInArray = Not IsError(Application.Match(itemSearched, aArray, False)) 'Slow on large arrays
Err.Clear: On Error GoTo 0
End If
End Function