|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
if条件用变量代替,出现类型不匹配?请大神帮忙看看有没有解决方法,感谢!
zdh(bb, 1)变量是组合的文本,用于做为if条件进行判断,
Sub sx()
Dim j&, k&, ff&, i&, aa, bb, aa1
Dim shn As String, kfbm As String, yn As String, jes() As Long ', fb2 As String
Dim sh As Worksheet
Dim wthz(), aj(), sj(), zdh()
'Application.ScreenUpdating = False '关闭屏幕更新
Set Twb = ThisWorkbook
Twb.Activate
Twb.Worksheets("条件").Select
row2 = Sheets("条件").[B65536].End(xlUp).Row '工作表行数
col2 = Sheets("条件").Cells(1, 256).End(xlToLeft).Column '工作表列数
ReDim sj(1 To row2 - 1, 1 To col2) '用于存放数据区域
ReDim zdh(1 To row2 - 1, 1 To 2) '用于存放组合后的条件和结果
sj = Range(Cells(2, 1), Cells(row2, col2))
For ff = 3 To row2 - 1
For aa = 1 To col2
'MsgBox sj(2, aa)
If Len(sj(ff, aa)) = 0 Then
Else
Select Case sj(2, aa)
Case "="
If Len(zdh(ff, 1)) > 1 Then
zdh(ff, 1) = zdh(ff, 1) & " and " & sj(1, aa) & sj(2, aa) & """" & sj(ff, aa) & """ "
Else
zdh(ff, 1) = sj(1, aa) & sj(2, aa) & """" & sj(ff, aa) & """ "
End If
Case "InStr"
If Len(zdh(ff, 1)) > 1 Then
zdh(ff, 1) = zdh(ff, 1) & " and " & sj(2, aa) & "( 1, " & sj(1, aa) & ", " & """" & sj(ff, aa) & """) > 0 "
Else
zdh(ff, 1) = sj(2, aa) & "( 1, " & sj(1, aa) & ", " & """" & sj(ff, aa) & """) > 0 "
End If
Case Is = "<"
If Len(zdh(ff, 1)) > 1 Then
zdh(ff, 1) = zdh(ff, 1) & " and " & sj(1, aa) & sj(2, aa) & sj(ff, aa) & " "
Else
zdh(ff, 1) = sj(1, aa) & sj(2, aa) & sj(ff, aa) & " "
End If
Case Is = ">"
If Len(zdh(ff, 1)) > 1 Then
zdh(ff, 1) = zdh(ff, 1) & " and " & sj(1, aa) & sj(2, aa) & sj(ff, aa) & " "
Else
zdh(ff, 1) = sj(1, aa) & sj(2, aa) & sj(ff, aa) & " "
End If
End Select
End If
Next
zdh(ff, 2) = sj(ff, col2)
Next
Twb.Worksheets("检查").Select
row1 = Sheets("检查").[A65536].End(xlUp).Row '工作表行数
ReDim wthz(1 To row1 - 2) '用于记录问题汇总
ReDim aj(1 To row1 - 2, 1 To 24) '用于存放数据区域
aj = Range(Cells(3, 1), Cells(row1, 24))
For kk = 1 To row1 - 2 '遍历数组每一行
For bb = 3 To row2 - 1
If zdh(bb, 1) Then ‘此处出现类型不匹配提示
If InStr(1, wthz(kk), zdh(bb, 2)) > 0 Then
Else
wthz(kk) = wthz(kk) & zdh(bb, 2)
End If
End If '
Next
Next
Sheets("检查").Cells(3, 8).Resize(UBound(wthz), 1) = Application.WorksheetFunction.Transpose(wthz)
End Sub
|
|