2017-05-23 7 views
0

こんにちは、私は可能な限りここでいくつかの助けが必要です。私は3つのボタンを作ろうとしていますが、各ボタンはトップラインとボトムラインを描きます(私はエクセルファイルも提供します)。ボーダーを描画するvbaがスペースのあるボタンで優秀

最初のボタンは5行の中で上と下を描画します。

2番目のボタンは、10行の内側に上端と下端を描画します。

3番目のボタンは、20行の中に上端と下端を描画します。

私が達成しようとしているもの: ボタン1を押して、すでに境界線が描画されている場合は1を押します。境界線を描画する場合は、そして、私はButton1を押したかどうボタン2.またはボタン3.

次に、同じ....の間に2行のスペースを保持した後、再び描く..私は、私はいくつかの助けを大好きだVBAで新しいです。 ...

ub Macro2() 
' 
' Macro2 Macro 
' 

' 
    Range("A13:BD23").Select 
    Selection.Borders(xlDiagonalDown).LineStyle = xlNone 
    Selection.Borders(xlDiagonalUp).LineStyle = xlNone 
    Selection.Borders(xlEdgeLeft).LineStyle = xlNone 
    With Selection.Borders(xlEdgeTop) 
     .LineStyle = xlContinuous 
     .ColorIndex = xlAutomatic 
     .TintAndShade = 0 
     .Weight = xlThick 
    End With 
    With Selection.Borders(xlEdgeBottom) 
     .LineStyle = xlContinuous 
     .ColorIndex = xlAutomatic 
     .TintAndShade = 0 
     .Weight = xlThick 
    End With 
    Selection.Borders(xlEdgeRight).LineStyle = xlNone 
    Selection.Borders(xlInsideVertical).LineStyle = xlNone 
    Selection.Borders(xlInsideHorizontal).LineStyle = xlNone 
    Range("A27").Select 
    ActiveWindow.SmallScroll Down:=12 
    Range("A27").Select 
End Sub 
Sub Macro1() 
' 
' Macro1 Macro 
' 

' 
    Range("A4:J8").Select 
    Selection.Borders(xlDiagonalDown).LineStyle = xlNone 
    Selection.Borders(xlDiagonalUp).LineStyle = xlNone 
    Selection.Borders(xlEdgeLeft).LineStyle = xlNone 
    With Selection.Borders(xlEdgeTop) 
     .LineStyle = xlContinuous 
     .ColorIndex = xlAutomatic 
     .TintAndShade = 0 
     .Weight = xlThick 
    End With 
    With Selection.Borders(xlEdgeBottom) 
     .LineStyle = xlContinuous 
     .ColorIndex = xlAutomatic 
     .TintAndShade = 0 
     .Weight = xlThick 
    End With 
    Selection.Borders(xlEdgeRight).LineStyle = xlNone 
    Selection.Borders(xlInsideVertical).LineStyle = xlNone 
    Selection.Borders(xlInsideHorizontal).LineStyle = xlNone 
    Range("C9").Select 
End Sub 
Sub Macro3() 
' 
' Macro3 Macro 
' 

' 
    Range("A26:P46").Select 
    ActiveWindow.SmallScroll Down:=-6 
    Selection.Borders(xlDiagonalDown).LineStyle = xlNone 
    Selection.Borders(xlDiagonalUp).LineStyle = xlNone 
    Selection.Borders(xlEdgeLeft).LineStyle = xlNone 
    With Selection.Borders(xlEdgeTop) 
     .LineStyle = xlContinuous 
     .ColorIndex = xlAutomatic 
     .TintAndShade = 0 
     .Weight = xlThick 
    End With 
    With Selection.Borders(xlEdgeBottom) 
     .LineStyle = xlContinuous 
     .ColorIndex = xlAutomatic 
     .TintAndShade = 0 
     .Weight = xlThick 
    End With 
    Selection.Borders(xlEdgeRight).LineStyle = xlNone 
    Selection.Borders(xlInsideVertical).LineStyle = xlNone 
    Selection.Borders(xlInsideHorizontal).LineStyle = xlNone 
    Range("G34").Select 
    ActiveWindow.SmallScroll Down:=-15 
End Sub 

DLのLINK: https://mega.nz/#!sgkVATKQ!k-Nq5gpKf4NfW2afEM8wpg_T5RFqT6y2_iqH7lDTM40

+0

どのボタンが最初に押されても、ハードコードされた範囲を開始点として使用し、その後に「前回」の範囲から2行のオフセットを使用する必要がありますか?しかし、さまざまな幅を保つ? –

+0

これで私のファイルを作ろうとしているのですが...行間にスペースを追加する方法はわかりませんが、前のボーダーをカウントする方法はわかりません。 – maxxi

答えて

0

ない私は完全にあなたの説明に従ってください、これを試してみてください。

EDITは - あなたは、最初からやり直すことができるように、「最後の範囲を」リセットする方法を追加しました。

Option Explicit 

Sub DoFive() 
    DoBorders Range("A4:J8") 
End Sub 

Sub DoTen() 
    DoBorders Range("A13:BD23") 
End Sub 

Sub DoTwenty() 
    DoBorders Range("A26:P46") 
End Sub 

'this is called to reset the starting point to whatever is passed. 
Sub ResetStart() 
    DoBorders Nothing 
End Sub 


Sub DoBorders(rng As Range) 
    Dim useRange As Range 
    Static lastRange As Range 

    'handle resetting the "last range" 
    If rng Is Nothing Then 
     Set lastRange = Nothing 
     Exit Sub 
    End If 

    If lastRange Is Nothing Then 
     Set useRange = rng 

    Else 
     Set useRange = lastRange.Cells(1).Offset(lastRange.Rows.Count + 2, 0) _ 
            .Resize(rng.Rows.Count, rng.Columns.Count) 
    End If 

    Set lastRange = useRange 'save for next call 

    With useRange 
     .Borders.LineStyle = xlNone 'remove all borders 
     With .Borders(xlEdgeTop) 
      .LineStyle = xlContinuous 
      .ColorIndex = xlAutomatic 
      .TintAndShade = 0 
      .Weight = xlThick 
     End With 
     With .Borders(xlEdgeBottom) 
      .LineStyle = xlContinuous 
      .ColorIndex = xlAutomatic 
      .TintAndShade = 0 
      .Weight = xlThick 
     End With 
    End With 

End Sub 
+0

はい、はい、はい!!!!!それはまさに私が望んでいた方法です、ありがとうございました! – maxxi

関連する問題