用vb向excel添加数据的一个问题

yumuyang 2006-11-13 03:18:21
我读取数据的代码是:
Dim row As Integer
Dim xlApp As Excel.Application
Dim xlbook As Excel.Workbook
Dim xlsheet As Excel.Worksheet

Set xlApp = CreateObject("Excel.Application")
Set xlbook = xlApp.Workbooks.Open("C:\ouwei.xls")
Set xlsheet = xlbook.Worksheets(1)
row = 2
Do Text1.Text > "0"
If Text1.Text = xlsheet.Cells(row, 1) Then
Text2.Text = xlsheet.Cells(row, 2)
Text3.Text = xlsheet.Cells(row, 3)
Text4.Text = xlsheet.Cells(row, 4)
Text5.Text = xlsheet.Cells(row, 5)
Text6.Text = xlsheet.Cells(row, 6)
Text7.Text = xlsheet.Cells(row, 7)
Text8.Text = xlsheet.Cells(row, 8)
Text9.Text = xlsheet.Cells(row, 9)
Text10.Text = xlsheet.Cells(row, 10)
End If
row = row + 1
Loop

现在我想向这个excel文件添加数据,如果text1=(row,1)则弹出对话框“已有此编号”并不对数据进行操作,如果text1不等于(row,1),则向excel添加数据(判断数据有9行就在第10行添加,有10行就向第11行添加。。。类推,最多添加到第150行),谁能帮忙解决一下,谢谢!
...全文
144 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
yumuyang 2006-11-13
  • 打赏
  • 举报
回复
zzyong00 非常感谢
zzyong00 2006-11-13
  • 打赏
  • 举报
回复
又错了
row = 0
dim flag as boolean
Do while xlsheet.Cells(row+1, 1)<> ""
row = row + 1
If Text1.Text = xlsheet.Cells(row, 1) Then
msgbox “已有此编号”
flag=true
End If
Loop

if not flag then xlsheet.Cells(row+1, 1)="你要添加的内容"
zzyong00 2006-11-13
  • 打赏
  • 举报
回复
row = 0
dim flag as boolean
Do while xlsheet.Cells(row+1, 1)<> ""
row = row + 1
If Text1.Text = xlsheet.Cells(row, 1) Then
msgbox “已有此编号”
flag=true
End If
Loop

if flag then xlsheet.Cells(row+1, 1)="你要添加的内容"
zzyong00 2006-11-13
  • 打赏
  • 举报
回复
row = 0
dim flag as boolean
Do while xlsheet.Cells(row+1, 1)<> ""
row = row + 1
If Text1.Text = xlsheet.Cells(row, 1) Then
msgbox “已有此编号”
flag=true
End If
Loop

xlsheet.Cells(row+1, 1)="你要添加的内容"

1,216

社区成员

发帖
与我相关
我的任务
社区描述
VB 数据库(包含打印,安装,报表)
社区管理员
  • 数据库(包含打印,安装,报表)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧