Sub pp()
Dim i As Integer
Dim totalRows As Integer
Dim aa As String
Dim bb As String
Dim cc As String
totalRows = Sheets(1).Range("a65536").End(xlUp).Row '第1个页面的有效数据行数
MsgBox ("开始处理: " & "数据总行数" & (totalRows - 1))
'检查数据
For i = 2 To totalRows
aa = Sheets(1).Cells(i, "A")
If checkData(i, totalRows, aa) = False Then
Exit Sub
End If
Next
'创建文件
Dim fso, testfile
Dim strTab As String
strTab = Chr$(9)
Set fso = CreateObject("scripting.filesystemobject") '指明一个对象
Set testfile = fso.createtextfile("datanice.txt", True) '指明创建目录和文件类型
'循环第1个页面所有行
For i = 2 To totalRows
'获取第1个页面值
aa = Sheets(1).Cells(i, "A")
bb = Sheets(1).Cells(i, "B")
cc = Sheets(1).Cells(i, "C")
'写入文件
testfile.writeline (aa + strTab + bb + strTab + cc) '指明创建方式
Next
'关闭文件
testfile.Close
MsgBox ("处理完成! sheet1总行数" & (totalRows - 1))
End Sub
Function checkData(rowid As Integer, totalRows As Integer, data As String) As Boolean
Dim i As Integer
For i = 2 To totalRows
dm = Sheets(1).Cells(i, “A”)
If dm = data And i <> rowid Then
MsgBox (“第1列第” & (i) & “行与第” & (rowid) & “行数据项不得重复!” & “数据项:” + dm)
checkData = False
Exit Function
End If
Next
checkData = True
End Function