Home > Software engineering >  How to simplify the following code
How to simplify the following code

Time:03-03

The Set RNG=Range (myfind. Offset (1, 0), myfind. Offset (1, 2))

With RNG. Borders (xlEdgeLeft)
. Graphics.linestyle=xlContinuous
. ColorIndex=0
. TintAndShade=0
The Weight=xlThin
End With

With RNG. Borders (xlEdgeBottom)
. Graphics.linestyle=xlContinuous
. ColorIndex=0
. TintAndShade=0
The Weight=xlThin
End With

With RNG. Borders (xlEdgeRight)
. Graphics.linestyle=xlContinuous
. ColorIndex=0
. TintAndShade=0
The Weight=xlThin
End With


With RNG. Borders (xlInsideVertical)
. Graphics.linestyle=xlContinuous
. ColorIndex=0
. TintAndShade=0
The Weight=xlThin
End With

CodePudding user response:

Also don't say what, say to simplify
This code is not simplified have what problem?

Does it xlEdgeLeft xlEdgeBottom xlEdgeRight xlInsideVertical these constant out to see how much is the specific values, of sequence and looking for any way to write general formula, and then by cycle

CodePudding user response:

, four constants are respectively 7,9,10,11
Then


The Set RNG=Range (myfind. Offset (1, 0), myfind. Offset (1, 2))
Dim as long I
For I=7 to 11
If I & lt;> 8 then
With RNG. Borders (I)
. Graphics.linestyle=xlContinuous
. ColorIndex=0
. TintAndShade=0
The Weight=xlThin
End With
End the if
Next

Did not test well, myself can not give it a try

CodePudding user response:

Same parts make a whole, write heads, in times of need, make a call

CodePudding user response:

reference long0981 reply: 3/f
parts make a whole, the same writing heads, in times of need, do a call

I use the RNG.
The borders
. Graphics.linestyle
The borders
. Graphics.linestyle
So write wrong

CodePudding user response:

Qq_44093147
reference 4 floor response:
Quote: refer to the third floor long0981 response:
parts make a whole, the same writing heads, in times of need, do a call

I use the RNG.
The borders
. Graphics.linestyle
The borders
. Graphics.linestyle
Write wrong


You write like that, of course is wrong,
 With Rng. Borders 
. Graphics.linestyle=xlContinuous
. ColorIndex=0
. TintAndShade=0
The Weight=xlThin
End With

CodePudding user response:

Use process, can be simplified:
 
The Set RNG=Range (myfind. Offset (1, 0), myfind. Offset (1, 2))
Setborder RNG, xlEdgeLeft
Setborder RNG, xlEdgeBottom
Setborder RNG, xlEdgeRight
Setborder RNG, xlInsideVertical

Sub setborder (RNG, pos)
With RNG. Borders (pos)
. Graphics.linestyle=xlContinuous
. ColorIndex=0
. TintAndShade=0
The Weight=xlThin
End With
End sub
  •  Tags:  
  • VBA
  • Related