数量、单价、金额互算VBA
将下面的代码复制到快表VBA编辑器中测试。代码下面有对应模板下载
- Imports SpreadsheetGear
- Imports System.Windows.forms
- Namespace ExcelViewVBDotnet
- Public Class StandardInterface '自定义名称
- '预留位置1
- '预留位置2
- Dim AW As SpreadsheetGear.IWorkbook,Range As SpreadsheetGear.IRange
- Dim CF,TS,VW As Object,YN As String
- Public Sub Workbook_Open(OldRoot As Object,NewRoot As Object,Excel As SpreadsheetGear.Windows.Forms.WorkbookView)
- Excel.GetLock()
- AW = Excel.ActiveWorkbook
- Range = AW.ActiveWorksheet.Range
- Excel.ReleaseLock()
- '位置:2保存3新增4提交5退回6打印7预览8导出9捕获10上传图片11上传附件12插入行13插多行14删除行15查找16最后
- End Sub'打开时执行事件
- Public Sub RangeSelection(sender As Object,e As SpreadsheetGear.Windows.Forms.RangeSelectionChangedEventArgs)
- End Sub'单元格选择后执行的事件
- Public Sub RangeChanged(sender As Object,e As SpreadsheetGear.Windows.Forms.RangeChangedEventArgs)
- if e.Range.Address <> YN Then'避免重复触发
- if e.Range.Intersect(Range("F_30")) IsNot Nothing then'数量触发金额
- if e.Range.Offset(0,1).Value IsNot Nothing And e.Range.Value IsNot NotHing then
- e.Range.Offset(0,2).Value = CType(e.Range.Offset(0,1).Value,Double) * CType(e.Range.Value,Double)
- end if
- Elseif e.Range.Intersect(Range("F_31")) IsNot Nothing then'单价触发金额
- if e.Range.Offset(0,-1).Value IsNot Nothing And e.Range.Value IsNot NotHing then
- YN = E.Range.Offset(0,1).Address
- e.Range.Offset(0,1).Value = CType(e.Range.Offset(0,-1).Value,Double) * CType(e.Range.Value,Double)
- end if
- Elseif e.Range.Intersect(Range("F_32")) IsNot Nothing then'金额触发单价
- if e.Range.Offset(0,-2).Value IsNot Nothing And e.Range.Value IsNot NotHing then
- if CType(e.Range.Offset(0,-2).Value,Double) <> 0 then
- YN = E.Range.Offset(0,-1).Address
- e.Range.Offset(0,-1).Value = CType(e.Range.Value,Double) / CType(e.Range.Offset(0,-2).Value,Double)
- end if
- end if
- End if
- Else
- YN = ""'还原触发判断
- End if
- End Sub'单元格编辑完成后执行事件
- Public Sub ButtunClick(sender As Object,e As SpreadsheetGear.Windows.Forms.ShapeActionEventArgs)
-
- End Sub'按钮/标签点击事件
- Public Sub FollowHyperlink(sender As Object)
-
- End Sub '暂不支持
- End Class
- '注:除事件字眼下可以自定义代码外的所有代码不允许改动,否则编译将有可能失败。
- End Namespace
复制代码
|
|
hessen