Home > Software engineering >  Vba expression is not defined in this context? Is not an error, amateurs do not understand, o god
Vba expression is not defined in this context? Is not an error, amateurs do not understand, o god

Time:09-22

 Sub find maximum and copied to the summary worksheet () 

Dim rGetRange As Range
If Sheets (2). The Range (" B30) & gt; Sheets (2). The Range (" B100 ") Then
Dim a1 As an Integer, a2 As an Integer, a3 As Integer
A1=Sheets (1). The Range (" a2 "). The Value
A2=Sheets (1). The Range (" a3 "). The Value
A3=Sheets (1). The Range (" a4 "). The Value

Dim r1 As Long, r2 As Long, r3 As Long, r4 As Long
Arr_a=Array (a1, a2)
R1=Sheets (2). The Columns (1). The Find (arr_a (0),,, xlWhole, xlByRows, xlPrevious). Row '1004
R2=Sheets (2). The Columns (1). The Find (arr_a (1),,, xlWhole, xlByRows, xlPrevious). Row
Sheets (2). Activate
The Set rng9=Sheets (2). The Range (Cells (r1, 122), Cells (r2, 122))
Set rGetRange=rng9. Find (Application. Max (rng9),,,,, xlByRows xlPrevious) 'return to nothing, there is a problem statement is this!!!!!!!!!!!!!!!!!!!!!!!!!!!
Set rGetRange=rng9. Find (Application. Max (rng9),,,,, xlPrevious) 'return nothing
If Not rGetRange Is Nothing Then Rows (rGetRange). The Font. ColorIndex=4 'If Not rGetRange Is Nothing Then Rows (rGetRange. Row). The Font. ColorIndex=4
The Set rng9=Nothing
Arr_b=Array (a2, a3)
R3=Columns (1). The Find (arr_b (0),,, xlWhole, xlByRows, xlPrevious). Row
R4=Columns (1). The Find (arr_b (1),,, xlWhole, xlByRows, xlPrevious). Row
Sheets (2). Activate
Set rng9=Sheets (2). The Range (Cells (r3, 122), Cells (r4, 122))
The Set rGetRange=rng9. Find (Application. Max (rng9),,,,, xlByRows xlPrevious)
If Not rGetRange Is Nothing Then Rows (rGetRange). The Font. ColorIndex=4

The Set rng9=Nothing

The Else


Dim a4 As an Integer, the a5 As an Integer, a6 As an Integer, the a7 As Long
A4=Sheets (2) Cells (3, 1). The Value
A7=Sheets (2). The Range (" A65536 "). The End (xlUp). The Value
A5=Sheets (1) Cells (2, 1). The Value
A6=Sheets (1) Cells (3, 1). The Value

Dim r5 As Long, r6 As Long, r7 As Long, the r8 As Long, r9 As Long, r10 As Long
Arr_c=Array (a4, a5)
R5=Sheets (2). The Columns (1). The Find (arr_c (0),,, xlWhole, xlByRows, xlPrevious). Row
R6=Sheets (2). The Columns (1). The Find (arr_c (1),,, xlWhole, xlByRows, xlPrevious). Row
Sheets (2). Activate
Set rng9=Sheets (2). The Range (Cells (r5, 122), Cells (r6, 122))
Set rGetRange=rng9. Find (Application. Max (rng9),,,,, xlByRows xlPrevious) 'sometimes return nothing sometimes does not return but value error
If Not rGetRange Is Nothing Then Rows (rGetRange). The Font. ColorIndex=4
The Set rng9=Nothing
Arr_d=Array (a5 and a6)
R7=Sheets (2). The Columns (1). The Find (arr_d (0),,, xlWhole, xlByRows, xlPrevious). Row
The r8=Sheets (2). The Columns (1). The Find (arr_d (1),,, xlWhole, xlByRows, xlPrevious). Row
Sheets (2). Activate
Set rng9=Sheets (2). The Range (Cells (r7, 122), Cells (r8, 122))
The Set rGetRange=rng9. Find (Application. Max (rng9),,,,, xlByRows xlPrevious)
If Not rGetRange Is Nothing Then Rows (rGetRange). The Font. ColorIndex=4
The Set rng9=Nothing
Arr_e=Array (a6, a7)
R9=Sheets (2). The Columns (1). The Find (arr_e (0),,,, xlByRows, xlPrevious). Row
R10=Sheets (2). The Columns (1). The Find (arr_e (1),,,, xlByRows, xlPrevious). Row
Sheets (2). Activate
Set rng9=Sheets (2). The Range (Cells (r9, 122), Cells (122), r10)
The Set rGetRange=rng9. Find (Application. Max (rng9),,,,, xlByRows xlPrevious)
If Not rGetRange Is Nothing Then Rows (rGetRange). The Font. ColorIndex=4
The Set rng9=Nothing
End the If

Dim rng6 As Range 'copy
Dim rng5 As Range
Dim cel4 As Range
Dim n4 interchange As Long
Dim b4 %
Dim c4 %

N4 interchange=Application. WorksheetFunction. CountA (Sheets (2). The Range (" DR: DR ")) 'computing DR list of how many rows
C4=7
The Set rng6=Sheets (2). The Columns (122)
The Set rng5=rng6. Columns (122)
Sheets (1). The Range (a7). Value="https://bbs.csdn.net/topics/MAX"
For b4=1 To n4 interchange 'bug
For Each cel4 rng6. In Rows (b4) Cells
If cel4. Characters (Start:=b4, Length:=1). The Font. ColorIndex=4 Then 'bugs, how to change the Font color to the background color format
C4=c4 + 1
Sheets (2). Rows (b4). Copy Sheets (1). The Range (" a "& amp; C4) 'Sheets (1). The Range (" A1 "). Copy Sheet10. Rows (1)
The Exit For
End the If
Next
Next
End Sub


Problem statement comments have marked (is that many exclamation mark), executable program, not an error, but not what I want results, after the monitoring window found, run to Set rng9=Sheets (2). The Range (Cells (r1, 122), Cells (r2, 122)), rng9 returns a Range, run to Set rGetRange=rng9. Find (Application. Max (rng9),,,, xlByRows, xlPrevious), rGetRange return is nothing. In addition to monitor window shows Max (rng9) expression in the context of undefined,
Even to the next statement, rgetrange returned is still nothing, solving

CodePudding user response:

Should be WorksheetFunction. Max () not Application. The Max ()
And you have variable is undefined error code, in the code module at the beginning of a line Option Explicit

CodePudding user response:

Thank you for your reply, but after or Max (rng9) expression in the context of undefined
 Option Explicit 
Sub find maximum and copied to the summary worksheet ()

Dim rGetRange As Range
Dim rng9 As Range
'With Sheets (2)
If Sheets (2). The Range (" B30) & gt; Sheets (2). The Range (" B100 ") Then
Dim a1 As an Integer, a2 As an Integer, a3 As Integer
Dim arr_a (1) As an Integer
Dim arr_b (1) As an Integer
A1=Sheets (1). The Range (" a2 "). The Value
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  •  Tags:  
  • VBA
  • Related