VBA模块代码.docx

  1. 1、本文档共18页,可阅读全部内容。
  2. 2、有哪些信誉好的足球投注网站(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
VBA模块代码

我这儿excel2007的版本,编写的VBA程序不知道为什么在excel里保存不了,所以,我写到Word里了,VBA打开程序如下:打开一个excel,按alt+F11打开下面的界面双击sheet1在工作区编写代码就行了,Sub ***()*****End sub是固定的都得有,我这儿只有打印版没有电子版,下面是有一些程序,你试着看看。我介绍一下一些简单的语句,像Dim price as integer 就是定义price 作为整型变量,其他的也类似定义,你可以参照下面的例子。If语句不同c语言,他必须有 then ,end if对于for ,得有 to,next详细的你参考例子,有c语言作为基础,学起来不能够不费力,这儿只是一小部分程序,本来是有介绍图形界面的,但是excel2007不给力,没办法。下面一个例子:单引号是注释。要删除在B列中元素为0的元素所在的行,就是删去2,4,6,8,10行,程序为:Sub dele() dele是我们自己写的,可以改。Dim a As Integer 定义a作为整型变量Dim s As Integer 定义s作为整型变量Range(a1).CurrentRegion.Select 这儿我看了没太懂,我认为应该是选定区域,s = Selection.Rows.Count 计算行数Range(b1).Select 选定b1单元格For a = 1 To sIf ActiveCell.Value = 0 Then 判断是否为零ActiveCell.EntireRow.Delete 删除该行ElseActiveCell.Offset(1, 0).Select 选定同列下一个单元格End IfNextEnd Sub点击运行,得到:Sub ifthenand()Dim units As SingleDim price As IntegerConst string1 = To get a rebate you must buy an addtionalConst string2 = price must equal $7.00price = Range(c1).Valueunits = Range(c2).ValueIf price = 7 And units = 50 Thenrebate = (price * units) * 0.1Range(a4).Value = the rebate is:$ rebateEnd IfIf price = 7 And units 50 ThenRange(a4).Value = string1 50 - units units(s)End IfIf price 7 And units = 50 ThenRange(a4).Value = string2End IfIf price = 7 And units 50 ThenRange(a4).Value = you didnt meet the criteriaEnd IfEnd SubSub whattypeofday()Dim response As StringDim question As StringDim string1 As String, string2 As StringDim mydate As Datequestion = enter the date in the format mm/dd/yyystring1 = weekdaystring2 = weekendresponse = InputBox(question)mydate = Weekday(CDate(response))If mydate = 2 And mydate = 6 ThenMsgBox string1ElseMsgBox string2End IfEnd SubSub structure()Dim num, mystrnum = 1If num = 1 Thenmystr = number equal 1Debug.Print mystrElsemystr = number equal 2End IfEnd SubSub enterdata()Dim cell As ObjectDim string1 As StringOn Error GoTo veryendstring1 = select any cellSet cell = Application.InputBox(prompt:=string1, Type:=8).cell.SelectIf IsEmpty(ActiveCell) ThenMsgBox helloActiveCell.Offset(1, 0).Se

文档评论(0)

xcs88858 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

版权声明书
用户编号:8130065136000003

1亿VIP精品文档

相关文档