Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make cells look like buttons

Tags:

excel

vba

I am trying to make Excel cells look like buttons without actually inserting buttons.

For Each myCell In Range(BoardSize)
    With myCell
        .Borders.LineStyle = xlContinuous
        .Borders.Weight = xlThick
        .Borders.Color = RGB(110, 110, 110)
        .Interior.Color = RGB(180, 180, 180)
    End With

        myCell.Borders(xlEdgeTop).Color = RGB(255, 255, 255)
        myCell.Borders(xlEdgeLeft).Color = RGB(255, 255, 255)
Next myCell

It works for one cell:

enter image description here

but in a large range it looks like this:

enter image description here

What I want is something, without using actual command buttons, like:

enter image description here

like image 361
Yong Avatar asked Oct 31 '22 15:10

Yong


1 Answers

For Each mycell In Range(BoardSize)
isblack = mycell.Row Mod 2 = 0 Xor mycell.Column Mod 2 = 0
    With mycell
        .Borders.LineStyle = xlContinuous
        .Borders.Weight = xlThick
        .Borders.Color = RGB(110, 110, 110)
        .Interior.Color = RGB(180, 180, 180)
    End With
If Not isblack Then
        mycell.Borders(xlEdgeTop).Color = RGB(255, 255, 255)
        mycell.Borders(xlEdgeLeft).Color = RGB(255, 255, 255)
End If
Next mycell

Another version with a minor artifact. It skipps odd rows and odd columns

 Dim mycell As Range
For Each mycell In  Range(BoardSize)
evenrow = mycell.Row Mod 2 = 0
evencol = mycell.Column Mod 2 = 0
isblack = evenrow Xor evencol
    With mycell
        .Borders.LineStyle = xlContinuous
        .Borders.Weight = xlThick
        .Borders.Color = RGB(110, 110, 110)
        .Interior.Color = RGB(180, 180, 180)
    End With
If Not isblack Then
        mycell.Borders(xlEdgeTop).Color = RGB(255, 255, 255)
        mycell.Borders(xlEdgeLeft).Color = RGB(255, 255, 255)
End If
If evenrow Or evencol Then mycell.Borders.Color = RGB(180, 180, 180)
If evencol And mycell.ColumnWidth <> 0.1 Then mycell.ColumnWidth = 0.1 Else mycell.ColumnWidth = 5
If evenrow And mycell.RowHeight <> 1 Then mycell.RowHeight = 1 Else mycell.RowHeight = 30
Next mycell
like image 115
anefeletos Avatar answered Nov 15 '22 06:11

anefeletos