VB大神看看这段代码的问题,解决几个小问题 20
我想提取excel中的单元格进行计算,可是计算的结果并没有按照我输入的公式来进行,而且没有数据的单元格所在行居然也能算出结果!PrivateSubCommand1_Cli...
我想提取excel中的单元格进行计算,可是计算的结果并没有按照我输入的公式来进行,而且没有数据的单元格所在行居然也能算出结果!
Private Sub Command1_Click()
CommonDialog1.CancelError = True
'设置标志
CommonDialog1.Flags = cdlOFNHideReadOnly
'设置过滤器
CommonDialog1.Filter = "全部文件|*.*|表格文件|*.xls|"
'设置缺省的过滤器
CommonDialog1.FilterIndex = 2
CommonDialog1.ShowOpen
Dim ExcelApp As Excel.Application
Set ExcelApp = CreateObject("excel.application")
ExcelApp.Workbooks.Open (CommonDialog1.FileName)
With MSFlexGrid1
.Rows = ExcelApp.Sheets(1).UsedRange.Rows.Count
.Cols = 30
For r = 0 To .Rows - 1
For c = 2 To .Cols
If c = 2 Then
.TextMatrix(r, c - 2) = ExcelApp.Sheets(1).Cells(r + 1, c - 1)
Else
.TextMatrix(r, c - 2) = ExcelApp.Sheets(1).Cells(r + 1, c - 1)
End If
Next
Next
End With
ExcelApp.Quit
End Sub
Private Sub Command2_Click()
Dim x As Single
Dim ExcelApp As Excel.Application
Set ExcelApp = CreateObject("excel.application")
ExcelApp.Workbooks.Open (CommonDialog1.FileName)
With MSFlexGrid1
.Rows = ExcelApp.Sheets(1).UsedRange.Rows.Count
.Cols = 30
x = Val(Text2.Text)
For r = 1 To .Rows - 1
MSFlexGrid1.TextMatrix(r, 10) = x
MSFlexGrid1.TextMatrix(0, 10) = "biot系数"
Next
End With
End Sub
Private Sub Command3_Click()
Dim a As Single, c As Single, d As Single
Dim ExcelApp As Excel.Application
Set ExcelApp = CreateObject("excel.application")
ExcelApp.Workbooks.Open (CommonDialog1.FileName)
With MSFlexGrid1
.Rows = ExcelApp.Sheets(1).UsedRange.Rows.Count
.Cols = 30
For r = 1 To .Rows - 1
MSFlexGrid1.row = r
MSFlexGrid1.col = 7
b = 1000000 / (3.2 * a)
MSFlexGrid1.row = r
MSFlexGrid1.col = 4
c = CStr(r)
MSFlexGrid1.row = r
MSFlexGrid1.col = 10
d = CStr(r)
m = 0.8 * b - 0.9 + 0.6 * c - 0.07 * d ^ (0.5)
MSFlexGrid1.TextMatrix(r, 11) = m
MSFlexGrid1.TextMatrix(0, 11) = "横波波速"
Next
End With
End Sub
如图,我只想让biot系数那一列赋值到24行就完了(不是固定的24行,是读取的excel有几行就到第几行),而且24行以后的那些行明明没有数据,却能计算处结果,为什么,应该是0或者没有啊。求大神解决这几个问题 展开
Private Sub Command1_Click()
CommonDialog1.CancelError = True
'设置标志
CommonDialog1.Flags = cdlOFNHideReadOnly
'设置过滤器
CommonDialog1.Filter = "全部文件|*.*|表格文件|*.xls|"
'设置缺省的过滤器
CommonDialog1.FilterIndex = 2
CommonDialog1.ShowOpen
Dim ExcelApp As Excel.Application
Set ExcelApp = CreateObject("excel.application")
ExcelApp.Workbooks.Open (CommonDialog1.FileName)
With MSFlexGrid1
.Rows = ExcelApp.Sheets(1).UsedRange.Rows.Count
.Cols = 30
For r = 0 To .Rows - 1
For c = 2 To .Cols
If c = 2 Then
.TextMatrix(r, c - 2) = ExcelApp.Sheets(1).Cells(r + 1, c - 1)
Else
.TextMatrix(r, c - 2) = ExcelApp.Sheets(1).Cells(r + 1, c - 1)
End If
Next
Next
End With
ExcelApp.Quit
End Sub
Private Sub Command2_Click()
Dim x As Single
Dim ExcelApp As Excel.Application
Set ExcelApp = CreateObject("excel.application")
ExcelApp.Workbooks.Open (CommonDialog1.FileName)
With MSFlexGrid1
.Rows = ExcelApp.Sheets(1).UsedRange.Rows.Count
.Cols = 30
x = Val(Text2.Text)
For r = 1 To .Rows - 1
MSFlexGrid1.TextMatrix(r, 10) = x
MSFlexGrid1.TextMatrix(0, 10) = "biot系数"
Next
End With
End Sub
Private Sub Command3_Click()
Dim a As Single, c As Single, d As Single
Dim ExcelApp As Excel.Application
Set ExcelApp = CreateObject("excel.application")
ExcelApp.Workbooks.Open (CommonDialog1.FileName)
With MSFlexGrid1
.Rows = ExcelApp.Sheets(1).UsedRange.Rows.Count
.Cols = 30
For r = 1 To .Rows - 1
MSFlexGrid1.row = r
MSFlexGrid1.col = 7
b = 1000000 / (3.2 * a)
MSFlexGrid1.row = r
MSFlexGrid1.col = 4
c = CStr(r)
MSFlexGrid1.row = r
MSFlexGrid1.col = 10
d = CStr(r)
m = 0.8 * b - 0.9 + 0.6 * c - 0.07 * d ^ (0.5)
MSFlexGrid1.TextMatrix(r, 11) = m
MSFlexGrid1.TextMatrix(0, 11) = "横波波速"
Next
End With
End Sub
如图,我只想让biot系数那一列赋值到24行就完了(不是固定的24行,是读取的excel有几行就到第几行),而且24行以后的那些行明明没有数据,却能计算处结果,为什么,应该是0或者没有啊。求大神解决这几个问题 展开
- 你的回答被采纳后将获得:
- 系统奖励15(财富值+成长值)+难题奖励10(财富值+成长值)+提问者悬赏20(财富值+成长值)
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询