绘制垂直边框但保留先前输入的计数

时间:2017-05-28 19:14:15

标签: excel excel-vba vba

我对VBA很陌生我仍然想知道如何让它继续下去。 我不知道如何在每次按下按钮时使垂直边框重复,但不能在同一个地方重复。

示例:

我按下按钮5 - >像表格一样的文字输入 - >绘制垂直线直到文本停止。

我现在按下按钮15 - >像表格一样的文字输入 - >绘制垂直线直到文本停止。

我将uppload文件供您查看更好的代码......

代码:

Option Explicit

Sub DoFive()
Dim LRow As Long                ' Row in which to place data

' Initalize Data
LRow = Range("B" & Rows.Count).End(xlUp).Row        ' Current last row with data

If LRow = 0 Then                                    ' It's the first set
    LRow = 4
Else
    LRow = LRow + 3                                 ' It's a follow-on set
End If

' Put in the borders
DoBorders Range("A" & LRow & ":AM" & LRow + 5)       ' Calculate the new range
Cells(LRow, "B").Interior.ColorIndex = 16
Cells(LRow, "E").Interior.ColorIndex = 50
Cells(LRow, "F").Interior.ColorIndex = 43
Cells(LRow, "A").Interior.ColorIndex = 22
Cells(LRow, "D").Interior.ColorIndex = 22
Cells(LRow, "C").Interior.ColorIndex = 45
Cells(LRow, "N").Interior.ColorIndex = 50
Cells(LRow, "H").Interior.ColorIndex = 45
Cells(LRow, "I").Interior.ColorIndex = "19"
Cells(LRow, "J").Interior.ColorIndex = "19"
Cells(LRow, "K").Interior.ColorIndex = "19"
Cells(LRow, "L").Interior.ColorIndex = "19"
Cells(LRow, "M").Interior.ColorIndex = "19"
Cells(LRow + 1, "H").Interior.ColorIndex = "3"
Cells(LRow + 2, "H").Interior.ColorIndex = "3"
Cells(LRow + 3, "H").Interior.ColorIndex = "3"
Cells(LRow + 4, "H").Interior.ColorIndex = "3"
Cells(LRow + 5, "H").Interior.ColorIndex = "3"

' Fill the new range with data
Cells(LRow, "A").Value = "Bought At"
Cells(LRow, "B").Value = "#"
Cells(LRow, "C").Value = "Name of Stock"
Cells(LRow, "D").Value = "Sell After"
Cells(LRow, "E").Value = "Sold Date"
Cells(LRow, "F").Value = "Profit"
Cells(LRow, "H").Value = "Name"
Cells(LRow, "I").Value = "1"
Cells(LRow, "J").Value = "2"
Cells(LRow, "K").Value = "3"
Cells(LRow, "L").Value = "4"
Cells(LRow, "M").Value = "5"
Cells(LRow, "N").Value = "Data"

Cells(LRow + 1, "B").Value = "1"
Cells(LRow + 2, "B").Value = "2"
Cells(LRow + 3, "B").Value = "3"
Cells(LRow + 4, "B").Value = "4"
Cells(LRow + 5, "B").Value = "5"

Cells(LRow + 1, "H").Value = "Price"
Cells(LRow + 2, "H").Value = "Price"
Cells(LRow + 3, "H").Value = "Price"
Cells(LRow + 4, "H").Value = "Price"
Cells(LRow + 5, "H").Value = "Price"

End Sub

Sub DoEight()
Dim LRow As Long                ' Row in which to place data

' Initalize Data
LRow = Range("B" & Rows.Count).End(xlUp).Row        ' Current last row with data

If LRow = 0 Then                                    ' It's the first set
    LRow = 4
Else
    LRow = LRow + 3                                 ' It's a follow-on set
End If

' Put in the borders
DoBorders Range("A" & LRow & ":AM" & LRow + 8)       ' Calculate the new range
Cells(LRow, "B").Interior.ColorIndex = 16
Cells(LRow, "E").Interior.ColorIndex = 50
Cells(LRow, "F").Interior.ColorIndex = 43
Cells(LRow, "A").Interior.ColorIndex = 22
Cells(LRow, "D").Interior.ColorIndex = 22
Cells(LRow, "C").Interior.ColorIndex = 45
Cells(LRow, "Q").Interior.ColorIndex = 50
Cells(LRow, "H").Interior.ColorIndex = 45
Cells(LRow, "I").Interior.ColorIndex = "19"
Cells(LRow, "J").Interior.ColorIndex = "19"
Cells(LRow, "K").Interior.ColorIndex = "19"
Cells(LRow, "L").Interior.ColorIndex = "19"
Cells(LRow, "M").Interior.ColorIndex = "19"
Cells(LRow, "N").Interior.ColorIndex = "19"
Cells(LRow, "O").Interior.ColorIndex = "19"
Cells(LRow, "P").Interior.ColorIndex = "19"
Cells(LRow + 1, "H").Interior.ColorIndex = "3"
Cells(LRow + 2, "H").Interior.ColorIndex = "3"
Cells(LRow + 3, "H").Interior.ColorIndex = "3"
Cells(LRow + 4, "H").Interior.ColorIndex = "3"
Cells(LRow + 5, "H").Interior.ColorIndex = "3"
Cells(LRow + 6, "H").Interior.ColorIndex = "3"
Cells(LRow + 7, "H").Interior.ColorIndex = "3"
Cells(LRow + 8, "H").Interior.ColorIndex = "3"
' Fill the new range with data
Cells(LRow, "A").Value = "Bought At"
Cells(LRow, "B").Value = "#"
Cells(LRow, "C").Value = "Name of Stock"
Cells(LRow, "D").Value = "Sell After"
Cells(LRow, "E").Value = "Sold Date"
Cells(LRow, "F").Value = "Profit"
Cells(LRow, "H").Value = "Name"
Cells(LRow, "I").Value = "1"
Cells(LRow, "J").Value = "2"
Cells(LRow, "K").Value = "3"
Cells(LRow, "L").Value = "4"
Cells(LRow, "M").Value = "5"
Cells(LRow, "N").Value = "6"
Cells(LRow, "O").Value = "7"
Cells(LRow, "P").Value = "8"
Cells(LRow, "Q").Value = "Data"

Cells(LRow + 1, "B").Value = "1"
Cells(LRow + 2, "B").Value = "2"
Cells(LRow + 3, "B").Value = "3"
Cells(LRow + 4, "B").Value = "4"
Cells(LRow + 5, "B").Value = "5"
Cells(LRow + 6, "B").Value = "6"
Cells(LRow + 7, "B").Value = "7"
Cells(LRow + 8, "B").Value = "8"

Cells(LRow + 1, "H").Value = "Price"
Cells(LRow + 2, "H").Value = "Price"
Cells(LRow + 3, "H").Value = "Price"
Cells(LRow + 4, "H").Value = "Price"
Cells(LRow + 5, "H").Value = "Price"
Cells(LRow + 6, "H").Value = "Price"
Cells(LRow + 7, "H").Value = "Price"
Cells(LRow + 8, "H").Value = "Price"
End Sub
Sub DoFifteen()
Dim LRow As Long                ' Row in which to place data

' Initalize Data
LRow = Range("B" & Rows.Count).End(xlUp).Row        ' Current last row with data

If LRow = 0 Then                                    ' It's the first set
    LRow = 4
Else
    LRow = LRow + 3                                 ' It's a follow-on set
End If

' Put in the borders
DoBorders Range("A" & LRow & ":AM" & LRow + 15)       ' Calculate the new range
Cells(LRow, "B").Interior.ColorIndex = 16
Cells(LRow, "E").Interior.ColorIndex = 50
Cells(LRow, "F").Interior.ColorIndex = 43
Cells(LRow, "A").Interior.ColorIndex = 22
Cells(LRow, "D").Interior.ColorIndex = 22
Cells(LRow, "C").Interior.ColorIndex = 45
Cells(LRow, "X").Interior.ColorIndex = 50
Cells(LRow, "H").Interior.ColorIndex = 45
Cells(LRow, "I").Interior.ColorIndex = "19"
Cells(LRow, "J").Interior.ColorIndex = "19"
Cells(LRow, "K").Interior.ColorIndex = "19"
Cells(LRow, "L").Interior.ColorIndex = "19"
Cells(LRow, "M").Interior.ColorIndex = "19"
Cells(LRow, "N").Interior.ColorIndex = "19"
Cells(LRow, "O").Interior.ColorIndex = "19"
Cells(LRow, "P").Interior.ColorIndex = "19"
Cells(LRow, "Q").Interior.ColorIndex = "19"
Cells(LRow, "R").Interior.ColorIndex = "19"
Cells(LRow, "S").Interior.ColorIndex = "19"
Cells(LRow, "T").Interior.ColorIndex = "19"
Cells(LRow, "U").Interior.ColorIndex = "19"
Cells(LRow, "V").Interior.ColorIndex = "19"
Cells(LRow, "W").Interior.ColorIndex = "19"
Cells(LRow + 1, "H").Interior.ColorIndex = "3"
Cells(LRow + 2, "H").Interior.ColorIndex = "3"
Cells(LRow + 3, "H").Interior.ColorIndex = "3"
Cells(LRow + 4, "H").Interior.ColorIndex = "3"
Cells(LRow + 5, "H").Interior.ColorIndex = "3"
Cells(LRow + 6, "H").Interior.ColorIndex = "3"
Cells(LRow + 7, "H").Interior.ColorIndex = "3"
Cells(LRow + 8, "H").Interior.ColorIndex = "3"
Cells(LRow + 9, "H").Interior.ColorIndex = "3"
Cells(LRow + 10, "H").Interior.ColorIndex = "3"
Cells(LRow + 11, "H").Interior.ColorIndex = "3"
Cells(LRow + 12, "H").Interior.ColorIndex = "3"
Cells(LRow + 13, "H").Interior.ColorIndex = "3"
Cells(LRow + 14, "H").Interior.ColorIndex = "3"
Cells(LRow + 15, "H").Interior.ColorIndex = "3"
' Fill the new range with data
Cells(LRow, "A").Value = "Bought At"
Cells(LRow, "B").Value = "#"
Cells(LRow, "C").Value = "Name of Stock"
Cells(LRow, "D").Value = "Sell After"
Cells(LRow, "E").Value = "Sold Date"
Cells(LRow, "F").Value = "Profit"
Cells(LRow, "H").Value = "Name"
Cells(LRow, "I").Value = "1"
Cells(LRow, "J").Value = "2"
Cells(LRow, "K").Value = "3"
Cells(LRow, "L").Value = "4"
Cells(LRow, "M").Value = "5"
Cells(LRow, "N").Value = "6"
Cells(LRow, "O").Value = "7"
Cells(LRow, "P").Value = "8"
Cells(LRow, "Q").Value = "9"
Cells(LRow, "R").Value = "10"
Cells(LRow, "S").Value = "11"
Cells(LRow, "T").Value = "12"
Cells(LRow, "U").Value = "13"
Cells(LRow, "V").Value = "14"
Cells(LRow, "W").Value = "15"
Cells(LRow, "X").Value = "Data"

Cells(LRow + 1, "B").Value = "1"
Cells(LRow + 2, "B").Value = "2"
Cells(LRow + 3, "B").Value = "3"
Cells(LRow + 4, "B").Value = "4"
Cells(LRow + 5, "B").Value = "5"
Cells(LRow + 6, "B").Value = "6"
Cells(LRow + 7, "B").Value = "7"
Cells(LRow + 8, "B").Value = "8"
Cells(LRow + 9, "B").Value = "9"
Cells(LRow + 10, "B").Value = "10"
Cells(LRow + 11, "B").Value = "11"
Cells(LRow + 12, "B").Value = "12"
Cells(LRow + 13, "B").Value = "13"
Cells(LRow + 14, "B").Value = "14"
Cells(LRow + 15, "B").Value = "15"

Cells(LRow + 1, "H").Value = "Price"
Cells(LRow + 2, "H").Value = "Price"
Cells(LRow + 3, "H").Value = "Price"
Cells(LRow + 4, "H").Value = "Price"
Cells(LRow + 5, "H").Value = "Price"
Cells(LRow + 6, "H").Value = "Price"
Cells(LRow + 7, "H").Value = "Price"
Cells(LRow + 8, "H").Value = "Price"
Cells(LRow + 9, "H").Value = "Price"
Cells(LRow + 10, "H").Value = "Price"
Cells(LRow + 11, "H").Value = "Price"
Cells(LRow + 12, "H").Value = "Price"
Cells(LRow + 13, "H").Value = "Price"
Cells(LRow + 14, "H").Value = "Price"
Cells(LRow + 15, "H").Value = "Price"

End Sub
Sub DoBorders(rng As Range)

With rng
    .Borders.LineStyle = xlNone
    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
文件的

和dl:https://mega.nz/#!BssHyJQa!HCwyJ5h0BbVeOJc4CkwohcoFAXJQ9bbfJ6q1PcQZuJs

我想要实现的目标: http://ibb.co/dHfYha

查看" Stock of Stock"," Sold Date"," Profit"之间的垂直边界,我不知道如何制作它们每次按下按钮5 8或15 ...

时重复

0 个答案:

没有答案