来自可变位置单元的和的计算

时间:2015-03-09 12:31:15

标签: vb.net excel

我想计算SUM这是我的代码:

 Dim lastrow As Integer 
 Dim lastcol As Integer, thiscol As Integer = CInt(j) 
 xlWorkSheet = CType(xlWorkBook.Sheets(ComboBox1.Text),Excel.Worksheet) 
 xlWorkSheet.Activate()
 xlApp.Visible = True 
 With xlWorkSheet 
    xlWorkSheet.Select() 
    j = (xlApp.Cells.SpecialCells(2).Row + 1 & vbCrLf&xlApp.Cells.SpecialCells(2).Column) 
    lastrow = .Cells(.Rows.Count, 1).End(Excel.XlDirection.xlUp).Row 
    lastcol = .Cells(1, .Columns.Count).End(Excel.XlDirection.xlToLeft).Column 
    For thiscol = j To lastcol 
        .Cells(lastrow + 1, thiscol).Value = _ 
        xlApp.Sum(.Range(.Cells(1, thiscol), .Cells(lastrow, thiscol))) 
    Next 
 End With 

我想使用变量' j'整数而不是字符串。

0 个答案:

没有答案