【VBA】杨辉三角
Private Sub Workbook_Open() Dim loopA As Integer
Dim loopB As Integer Dim loopNum As Integer
Dim topCell As Range loopNum = CInt(InputBox("input number", "title")) Cells.Select
'Selection.ClearContents
Selection.Delete Shift:=xlUp For loopA = To loopNum If loopA = Then
Cells(loopA, loopNum).Value = ""
Cells(loopA, loopNum).Interior.Color =
Set topCell = Cells(loopA, loopNum)
GoTo nextFor Else
For loopB = To loopNum * -
Call setRangeValue(Cells(loopA, loopB)) If loopA = loopNum Then
If Len(Cells(loopA, loopB).Value) > Then
Cells(loopA, loopB).Interior.Color =
End If
End If
Next loopB
End If
nextFor: Next loopA Cells.Select
'Cells.EntireColumn.AutoFit
Selection.ColumnWidth =
Cells.EntireRow.AutoFit
'Selection.RowHeight = 4 topCell.Activate
topCell.Select End Sub Public Sub setRangeValue(rag As Range) Dim bfLeftRange As Range
Dim bfRightRange As Range
Dim leftVal As Double
Dim rightVal As Double If rag.Column = Then
Set bfLeftRange = Cells(rag.Row - , rag.Column)
Else
Set bfLeftRange = Cells(rag.Row - , rag.Column - )
End If Set bfRightRange = Cells(rag.Row - , rag.Column + ) If Len(bfLeftRange.Value) = And Len(bfRightRange.Value) = Then
rag.Value = ""
GoTo SubEnd
Else
leftVal = CDbl(bfLeftRange.Value)
rightVal = CDbl(bfRightRange.Value)
rag.Value = leftVal + rightVal
If rag.Value = "" Then
rag.Interior.Color =
End If End If SubEnd: End Sub
【VBA】杨辉三角的更多相关文章
- [LeetCode] Pascal's Triangle II 杨辉三角之二
Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Return [1,3, ...
- [LeetCode] Pascal's Triangle 杨辉三角
Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5,Retur ...
- POJ2167Irrelevant Elements[唯一分解定理 组合数 杨辉三角]
Irrelevant Elements Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 2407 Accepted: 59 ...
- python生成器实现杨辉三角
def triangels(): """ 杨辉三角 """ lst = [1] n_count = 2 # 下一行列表长度 while Tr ...
- python 生成器生成杨辉三角
用Python写趣味程序感觉屌屌的,停不下来 #生成器生成展示杨辉三角 #原理是在一个2维数组里展示杨辉三角,空的地方用0,输出时,转化为' ' def yang(line): n,leng=0,2* ...
- HDNOIP201405杨辉三角
2016.1.27 试题描述 杨辉三角是形如如下的数字三角形: 1 1 1 1 2 1 …… 现在想求出杨辉三角第N行的N个数中,有多少个数能被给定的质数p整除. 输入 一行两个空格隔 ...
- Java的二维数组的应用及杨辉三角的编写
(1) 编写一个程序,生成一个10*10的二维随机整数数组,并将该数组的每行最大值保存于一个一维数组中,将每列平均值保存于另外一个一维数组中并分别输出. (2) 编程输出杨辉三角的前10行. 找出一个 ...
- POJ3187Backward Digit Sums[杨辉三角]
Backward Digit Sums Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6350 Accepted: 36 ...
- 杨辉三角用java实现
代码如下: public class ErArray { public static void main(String[] args) { //杨辉三角 int[][] num = new int[1 ...
- python 杨辉三角
前提:端点的数为1. 每个数等于它上方两数之和. 每行数字左右对称,由1开始逐渐变大. 第n行的数字有n项. 第n行数字和为2n-1. 第n行的m个数可表示为 C(n-1,m-1),即为从n-1个不同 ...
随机推荐
- day04列表
列表 内容详细 1.列表 公共 独有方法 删除 remove pop clear del区别 强制转换 #表示多个事物 users=["lili","Joe", ...
- 查询正在运行的请求及其后台对应SQL
SELECT a.event , s.actual_start_date , a.sid, a.serial#, sa.sql_fulltext , sa.sql_text , v.user_conc ...
- 【SpringBoot】整合定时任务和异步任务
========================10.SpringBoot整合定时任务和异步任务处理 =============================== 1.SpringBoot定时任务s ...
- 使用mysqlproxy实现mysql读写分离
先说一下什么是读写分离吧. 以三台虚拟机为例,搭建一主一从一代理,全部配置好之后,当从proxy插入数据时,该数据会同时插入主数据库,因为主从关系,从数据库也会有数据.当把从数据库执行slave st ...
- java_oop_方法2
基本和引用数据类型 存储方式 数据类型总结 jvm运行时数据区域 方法区 虚拟机栈! 本地方法栈 堆! 程序计数器 虚 ...
- lvs UDP端口负载均衡配置
! Configuration File for keepalived global_defs { notification_email { test@163.com } notification_e ...
- Ansible 快速部署 Zabbix 4
阅读本文章需要具有Ansible.Zabbix基础.本次教程基于如下环境: CentOS 7.x Zabbix 4.0 Ansible 2.5 服务器初始化 关闭防火墙.selinux,添加epel常 ...
- 1.2.2 Excel中手机号或身份证号批量加密星号
在对应的单元格中我们输入公式: =LEFT(C4,3)&"****"&RIGHT(C4,4)或=MID(C4,1,3)&"****"&a ...
- Zuul权限检验
一.达到的目标 /order/create 只能买家访问 /order/finish 只能卖家访问 /product/list 都能访问 二.创建User工程 1.创建user工程 选择的依赖 2.创 ...
- c#读sql server数据添加到MySQL数据库
using System;using System.Collections.Generic;using System.Text;using Console = System.Console;using ...