Sub DE ()
As Integer Dim I As an Integer, a, b As an Integer, c As an Integer, rn) As the Range, d As Integer
A=Sheets (" Jan "). The Application, CountA (Range (a: a))
For I=1 To 3
Application. The Sheets. The Add (Sheets (" Jan ")). The Name=I & amp; "Make"
Sheets (" Jan "). The Range (" a1, b1). Copy Sheets (I & amp; "Make") Cells (1, 1)
For Each rn In Sheets (" Jan "). The Range (" a1: "a10)
If an rn=I & amp; "Make" Then
C=Sheets (I & amp; "Make"). UsedRange. Rows. Count
Sheets (" Jan ".) Range (" a "& amp; Rn. Row & amp; ":" b & amp; Rn. Row). Copy Sheets (I & amp; "Make") Cells (1, 1). Offset (c)
End the If
Next
Next
End Sub
But after modified to the following code (only change the basic red two lines), will not be able to run (run to the red line or two excel automatically wrong), but by the range of variable reference is a cell can be used in place of the? Why can't run?
Sub DE ()
Dim I As an Integer, m As an Integer, n As an Integer, c As an Integer, rn) As the Range, d As Integer
M=Sheets (" Jan "). The Application, CountA (Range (a: a))
N=Sheets (" Jan "). The Application, CountA (Range (" 1 "))
For I=1 To 3
Application. The Sheets. The Add (Sheets (" Jan ")). The Name=I & amp; "Make"
Sheets (" Jan "). The Range (" a1, b1). Copy Sheets (I & amp; "Make") Cells (1, 1)
For Each rn In Sheets (" Jan "). The Range (cells (1, 1), cells (m, n))
If an rn=I & amp; "Make" Then
C=Sheets (I & amp; "Make"). UsedRange. Rows. Count
Sheets (" Jan "). The Range (Cells (c, 1), Cells (c, 2)). Copy Sheets (I & amp; "Make") Cells (1, 1). Offset (c)
End the If
Next
Next
End Sub
CodePudding user response:
The value of m and n out of the question?CodePudding user response:
Use the debug. Print verify the value of m and n yes,,,, so more entanglements ~ ~CodePudding user response:
All commented On the Error Resume Next statement, running in the VBA IDE,The error and then click the debugging, the cursor will stop error in the statement,
Or
In doubt may have a logical error statements in advance to set breakpoints, run through the breakpoint interrupt,
At this point can be used in the immediate window
? The variable name
Or
? The function name () function parameter
Or
Process (parameters)
Auxiliary debugging,
CodePudding user response:
What is the specific error message! Don't make it clear...For Each statement, behind the In keyword should give a "collection objects"!
And Sheets (" Jan "). The Range (cells (1, 1), cells (m, n)) just said "a zone" of a single object, rather than the "set", there must be illegal,
The Copy, to try this:
Sheets (" Jan "). The Range (Cells (c, 1), Cells (c, 2)). Copy Sheets (I & amp; "Make") Cells (1, 1)
CodePudding user response:
For Each rn In Sheets (" Jan "). The Range (cells (1, 1), cells (m, n))Change
For Each rn In Sheets (" Jan "). The Range ( Sheets (" Jan ".) cells (1, 1), Sheets (" Jan ".) cells (m, n))
CodePudding user response:
Questions are not sound,CodePudding user response:
Into Sheets (" Jan "). The Range (cells (1, 1). The address, cells (m, n). The address) try