我读取数据的代码是:
Dim row As Integer
Dim xlApp As Excel.Application
Dim xlbook As Excel.Workbook
Dim xlsheet As Excel.WorksheetSet 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行),谁能帮忙解决一下,谢谢!

解决方案 »

  1.   

    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
    Loopxlsheet.Cells(row+1, 1)="你要添加的内容"
      

  2.   

    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
    Loopif flag then xlsheet.Cells(row+1, 1)="你要添加的内容"
      

  3.   

    又错了
    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
    Loopif not flag then xlsheet.Cells(row+1, 1)="你要添加的内容"