一、For循环
基本用法
for (语句 1; 语句 2; 语句 3) {
要执行的代码块
}
function 读取(){
for(let RowNum=2;RowNum<=5;RowNum=RowNum+1){
console.log(Range("a"+RowNum).Value());
console.log(Range("b"+RowNum).Value());
console.log('-----------')
}
}
function 求和(){
for(let IntNum=2;IntNum<=5;IntNum++){
Range("d"+IntNum).Value2=Range("b"+IntNum).Value()+Range("c"+IntNum).Value()
}
}
function 读取工作表名称(){
for(let ShsC=1;ShsC<=Sheets.Count;ShsC++){
console.log(Worksheets(ShsC).Name)
}
}
function 九九乘法表(){
for(let a =1;a<=9;a++){
for(let b=1;b<=a;b++){
Cells(a,b).Value2=a+"X"+b+"="+a*b
}
}
}
for in循环
for/in语句可以读取数组中的下标(索引号),或者对象的属性。
function test1(){
var arr=[12,13,456,4564,45];//相当于[0:12,1:13,2:456,3:4564,4:45]
for(let intIndex in arr){
console.log(intIndex+"-"+arr[intIndex]);
}