小福利,用Excel vba设计一个变色小游戏

4 篇文章 0 订阅

小福利,用Excel vba设计一个变色小游戏

Option Explicit

Private Sub CommandButton1_Click()
Dim i, j
For i = 1 To 100
    For j = 1 To 100
     If i >= j Then
        If i Mod 2 = 1 And j Mod 2 = 1 Then
           Cells(i, j) = "zpsg"
           
           With Cells(i, j).Interior
             .Pattern = xlSolid
              .Color = vbGreen
           End With
        
        Else
            Cells(i, j) = i * j
            
        End If
            
        
     Else
        Cells(i, j) = ""
        
    End If
    
    Next j
    
Next i

End Sub

Private Sub CommandButton2_Click()

[a1:cv100] = ""
[a1:cv100].Interior.Color = vbWhite

End Sub

Private Sub CommandButton3_Click()
Dim i, j
For i = 1 To 100
    For j = 100 To 1 Step -1
     If i <= j Then
        If i Mod 2 = 1 And j Mod 2 = 1 Then
           Cells(i, j) = "zpsg"
           
           With Cells(i, j).Interior
             .Pattern = xlSolid
              .Color = vbRed
           End With
        
        Else
            Cells(i, j) = i * j
            
        End If
        
           
     Else
        Cells(i, j) = ""
        
    End If
    
    Next j
    
Next i


End Sub

Private Sub CommandButton4_Click()

Dim i, j
For i = 1 To 100
    For j = 1 To 100
     
    If i Mod 2 = 1 And j Mod 2 = 1 Then
           Cells(i, j) = "zpsg"
           
           With Cells(i, j).Interior
             .Pattern = xlSolid
              .Color = vbCyan
              
           End With
        
    Else
           Cells(i, j) = i * j
            
        
    End If
    
    Next j
    
Next i


End Sub

Private Sub CommandButton5_Click()


Dim i, j
For i = 1 To 100
    For j = 1 To 100
     
    If i Mod 2 = 0 And j Mod 2 = 0 Then
           Cells(i, j) = "zpsg"
           
           With Cells(i, j).Interior
             .Pattern = xlSolid
              .Color = vbBlue
              
              
           End With
        
    Else
           Cells(i, j) = i * j
            
        
    End If
    
    Next j
    
Next i


End Sub

Private Sub CommandButton6_Click()
Dim i, j
Dim r1
For i = 1 To 100 Step 3
    For j = 1 To 100 Step 3
     
    If i Mod 2 = 1 And j Mod 2 = 1 Then
           Set r1 = Range(Cells(i, j), Cells(i, j + 1))
           r1.Value = "zpsg"
           
           With r1.Interior
             .Pattern = xlSolid
              .Color = RGB(255, 0, 255)
              
           End With
        
    Else
           Cells(i, j) = i * j
            
        
    End If
    
    Next j
    
Next i
End Sub

在这里插入图片描述
如上图插入六个命令框,分别写入代码
效果展示如下
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值