Excel VBA编辑会员信息管理系统

 时间:2024-10-03 04:40:47

使用ExcelVBA编辑简单信息处理系统,是一件比较容易的事儿,比较容易上手。简单易用。ExcelVBA提供大量的组件以及函数,足以处理大部分办公问题。

Excel VBA编辑会员信息管理系统

工具/原料

Excel

方法/步骤

1、基本界面如下图:ListBox用于数据显示,Label显示标签,TextBox输入文本CommandButton按钮用于控制数据的更新、删除、添加。

Excel VBA编辑会员信息管理系统

2、定义窗体初始化:listbox显示数据PrivateSubUserForm_Initialize()Worksheets("Sheet1").Selectc=Worksheets("Sheet1").Range("a1").End(xlToRight).Columnr=Worksheets("Sheet1").Range("A65536").End(xlUp).RowListBox1.ColumnCount=cListBox1.RowSource=Worksheets("Sheet1").Range("A1:"&Chr(64+c)&r&"").AddressEndSub

Excel VBA编辑会员信息管理系统

3、定义查询按钮:PrivateSubCommandButton1_Click()IfTextBox1.Text=""ThenMsgBox"ÇëÊäÈëÐèÒª²éѯ»áÔ±ºÅ"ExitSubEndIfWithWorksheets("Sheet1")rs=rFori=2TorsIf.Cells(i,1)=TextBox1.TextThenTextBox1.Text=.Cells(i,1)TextBox2.Text=.Cells(i,2)TextBox3.Text=.Cells(i,3)rl=iExitForEndIfNextEndWithEndSub功能为查询匹配项并显示在相应的TextBox中

Excel VBA编辑会员信息管理系统

4、定义添加按钮:PrivateSubCommandB掼鸿乡羰utton2_Click()DimncsAsLongncs=Workshee墉掠载牿ts("Sheet1").Range("A65536").End(xlUp).Row+1WithWorksheets("Sheet1").Cells(ncs,1)=TextBox1.Text.Cells(ncs,2)=TextBox2.Text.Cells(ncs,3)=TextBox3.TextEndWithActiveWorkbook.SaveCallUserForm_InitializeTextBox1.Text=""TextBox2.Text=""TextBox3.Text=""EndSub功能为在最后一行添加数据,并清空TextBox

Excel VBA编辑会员信息管理系统

5、依次添加组件的方法:以下是整个程序的代码:DimcAs雉搽妤粲LongDimrAsLongDimrlAsLongPrivateSubComm锾攒揉敫andButton1_Click()IfTextBox1.Text=""ThenMsgBox"请输入需要查询会员号"ExitSubEndIfWithWorksheets("Sheet1")rs=rFori=2TorsIf.Cells(i,1)=TextBox1.TextThenTextBox1.Text=.Cells(i,1)TextBox2.Text=.Cells(i,2)TextBox3.Text=.Cells(i,3)rl=iExitForEndIfNextEndWithEndSubPrivateSubCommandButton2_Click()DimncsAsLongncs=Worksheets("Sheet1").Range("A65536").End(xlUp).Row+1WithWorksheets("Sheet1").Cells(ncs,1)=TextBox1.Text.Cells(ncs,2)=TextBox2.Text.Cells(ncs,3)=TextBox3.TextEndWithActiveWorkbook.SaveCallUserForm_InitializeTextBox1.Text=""TextBox2.Text=""TextBox3.Text=""EndSubPrivateSubCommandButton3_Click()c=ListBox1.ListIndex+1Ifc=0ThenMsgBox"请选择一条数据"ExitSubEndIfRows(c).DeleteEndSubPrivateSubCommandButton4_Click()IfTextBox1.Text=""AndTextBox2.Text=""AndTextBox3.Text=""Andr<>0ThenMsgBox"请先进行相应的数据查询"Elser=rlWithWorksheets("Sheet1").Cells(r,1)=TextBox1.Text.Cells(r,2)=TextBox2.Text.Cells(r,3)=TextBox3.TextActiveWorkbook.SaveUserForm_InitializeEndWithEndIfEndSubPrivateSubCommandButton5_Click()UnloadMeEndSubPrivateSubCommandButton6_Click()c=Worksheets("Sheet1").Range("a1").End(xlToRight).Column+1ad=InputBox("输入增加项名称","增加项","")Ifad<>""ThenWorksheets("Sheet1").Cells(1,c)=adEndIfEndSubPrivateSubListBox1_Click()EndSubPrivateSubUserForm_Click()EndSubPrivateSubUserForm_Initialize()Worksheets("Sheet1").Selectc=Worksheets("Sheet1").Range("a1").End(xlToRight).Columnr=Worksheets("Sheet1").Range("A65536").End(xlUp).RowListBox1.ColumnCount=cListBox1.RowSource=Worksheets("Sheet1").Range("A1:"&Chr(64+c)&r&"").AddressEndSub

Excel VBA编辑会员信息管理系统

6、窗体的控件由以下工具箱添加。并在thisworkbook中添加如下代码,引入菜单栏工具。便于启动。

Excel VBA编辑会员信息管理系统

Excel VBA编辑会员信息管理系统

7、实例运行:

Excel VBA编辑会员信息管理系统

Excel VBA编辑会员信息管理系统

Excel VBA编辑会员信息管理系统

Excel VBA编辑会员信息管理系统

Excel VBA编辑会员信息管理系统

Excel VBA编辑会员信息管理系统

怎样在蜀门中修炼元神 怎样维持良好的同事关系 超宽屋檐蜘蛛人够不到墙怎么办 罗百吉I MISS YOU歌词 门窗大师傅下料计算软件账套数据自动备份操作
热门搜索
降落伞图片 火车软座图片 狼少女与黑王子电影 虎头蜂图片 日韩美女图片