Ответ 1
Ячейки ссылаются на Activesheet, а не на "базу данных".
Set CR1_range = ws.Range(ws.Cells(5, CR1), ws.Cells(ws.Rows.count, CR1))
Этот код использовался, чтобы нормально работать, а затем внезапно он начал сбой при "методе" диапазона объекта "Сбой в работе"? ' Я не эксперт в VBA, но я могу обойти это. Что-то мне не хватает?
Public Sub Run_Count_Click()
'// Set Ranges
Dim Cr_1, CR1_range, _
Cr_2, CR2_range, _
Cr_3, CR3_range, _
Cr_4, CR4_range, _
Cr_5, CR5_range _
As Range
'// Set Integers
Dim CR1, V1, CR1_Result, _
CR2, V2, CR2_Result, _
CR3, V3, CR3_Result, _
CR4, V4, CR4_Result, _
CR5, V5, CR5_Result, _
total_result, _
total_result2, _
total_result3, _
total_result4, _
total_result5 _
As Integer
'Set Strings
Dim V_1, V_2, V_3, V_4, V_5 As String
Dim ws As Worksheet
Set ws = Worksheets("database")
'// Get Criteria From Form And Search Database Headers
Set Cr_1 = ws.Cells.Find(What:=Me.Count_Criteria_1.Value, After:=Cells(1, 1), MatchCase:=False)
If Not Cr_1 Is Nothing Then
CR1 = Cr_1.Column '//Set CR1 as the Column in which the Criteria Header was found
Else
MsgBox "Criteria 1 Has Not Been Found In The Database. Report Has Failed To Generate"
Exit Sub
End If
'// Get Variable Value From Form And Set Shortcode
V_1 = Me.Criteria_1_Variable.Value
Set CR1_range = ws.Range(Cells(5, CR1), Cells(Rows.count, CR1))
CR1_Result = Application.CountIf(CR1_range, V_1)
If Me.Count_Criteria_2 = "Any" Then
Me.Count_Result.visible = True
Me.Count_Result.Value = "Based On Your Search Criteria Of:" & vbNewLine & _
"How many occurences of [" & Me.Criteria_1_Variable.Value & "] in the category [" & Me.Count_Criteria_1.Value & _
"] have occured between the dates..." & vbNewLine & vbNewLine & "The Results Are: " & CR1_Result
Exit Sub
В этой строке код не работает:
Set CR1_range = ws.Range(Cells(5, CR1), Cells(Rows.count, CR1))
Спасибо заранее, ребята
Ячейки ссылаются на Activesheet, а не на "базу данных".
Set CR1_range = ws.Range(ws.Cells(5, CR1), ws.Cells(ws.Rows.count, CR1))
Недопустимый диапазон методов Excel VBA объекта _global?
Sub kar()
Dim i, j
For i = 8 To 15
For j = 9 To 15
If (Range("ji") = Range("jj") And Range("gi") = "خريد" And Range("gj") = "فروش" And (Abs(Range("ki") - Range("kj") <= 50))) Then
Range("ui") = -(Range("ki") - Range("kj")) * hi
Range("uj") = -(Range("ki") - Range("kj")) * hj
End If
If (Range("ji") = Range("jj") And Range("gi") = "فروش" And Range("gj") = "خريد" And (Abs(Range("ki") - Range("kj")) <= 50)) Then
Range("uj").Value = -(Range("ki") - Range("kj")) * hi
Range("ui").Value = -(Range("ki") - Range("kj")) * hj
End If
Next j
Next i
End Sub