以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- 代码 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=66593) |
-- 作者:发财 -- 发布时间:2015/4/10 8:44:00 -- 代码 For n As Integer = 5 To 54 If ws1.cells(6+i,n-2).Formula = "" Then ws1.cells(6+i,n-2).Value = Sheet1(n,3).Value End If If ws1.cells(6+i,n+48).Formula = "" Then ws1.cells(6+i,n+48).Value = Sheet1(n,7).Value End If Next For n As Integer = 6 To 35 If ws2.cells(6+i,n-3).Formula = "" Then ws2.cells(6+i,n-3).Value = sheet2(n,3).Value End If If ws2.cells(6+i,n+27).Formula = "" Then ws2.cells(6+i,n+27).Value = sheet2(n,7).Value End If Next 如何书写得简便点?
|
-- 作者:Bin -- 发布时间:2015/4/10 8:50:00 -- For n As Integer = 5 To 54 If ws1.cells(6+i,n-2).Formula = "" Then ws1.cells(6+i,n-2).Value = Sheet1(n,3).Value End If If ws1.cells(6+i,n+48).Formula = "" Then ws1.cells(6+i,n+48).Value = Sheet1(n,7).Value End If if n>=6 andalso n<=35 then If ws2.cells(6+i,n-3).Formula = "" Then ws2.cells(6+i,n-3).Value = sheet2(n,3).Value End If If ws2.cells(6+i,n+27).Formula = "" Then ws2.cells(6+i,n+27).Value = sheet2(n,7).Value End If end if Next 少遍历一次效率高点
|
-- 作者:发财 -- 发布时间:2015/4/10 11:03:00 -- For i As Integer = 0 To 5 Dim Ws & i As MSExcel.WorkSheet = Wb.WorkSheets(i) Next 这种情况应如何改才生效?
|
-- 作者:Bin -- 发布时间:2015/4/10 11:06:00 -- For i As Integer = 0 To 54 if i<=5 then end if if i>=5 then end if if i>=6 andalso n<=35 then end if
next |
-- 作者:发财 -- 发布时间:2015/4/10 11:10:00 -- For i As Integer = 0 To 5 Dim Ws & i As MSExcel.WorkSheet = Wb.WorkSheets(i) Next 这种情况应如何改才生效?
|
-- 作者:Bin -- 发布时间:2015/4/10 11:17:00 -- 变量不能这么定义,也不用这么定义 直接 这样 即可 每次都会生成新的,不会有重名问题. 如果希望使用 上一级 可以直接指定 Wb.WorkSheets(2) For i As Integer = 0 To 5 Dim Ws As MSExcel.WorkSheet = Wb.WorkSheets(i) Next |