|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
九台电脑(公) 发表于 2011-12-15 15:18
这些过客都是大傻,只有哥明白你的意思。
楼主的意思是单元格的字符串中有一个字符是TAB字符,是控制字符, ...
其实核心的代码没有那么长的。我写的是程序,所以有很多其它代码。这里把其它代码也附上。
Option Explicit
Private Const MAX_EMPTY_ROW As Integer = 5
Public myCliperBoard As New DataObject
'to get the data of a cell
Public Function GetData(sheet As Worksheet, ByVal iRow As Integer, ByVal iCol As Integer) As String
Dim s As String
Dim r As Range
Set r = sheet.Cells(iRow, iCol)
s = r.Value
GetData = s
End Function
'to get the data of a range
Public Function GetRangeData(r As Range) As String
Dim s As String
On Error Resume Next
s = r.Value
If Err.Number <> 0 Then
Debug.Print "Error(" & Err.Number & "):" & Err.Description & VBA.vbCrLf & Err.Source
End If
On Error GoTo 0
GetRangeData = s
End Function
'to make message
Public Function makeMessage(sheet As Worksheet, ByVal iRow As Integer, ByVal iCol As Integer) As String
Dim s As String
Dim sName As String
Dim sExpectedValue As String
Dim c As String
Dim iSkipCounter As Integer
'番号----列名----列----byte数----パディング----セパレータ----期望列値
Do While (True) 'loop for fields
sName = GetData(sheet, iRow, iCol + 1)
sExpectedValue = GetData(sheet, iRow, iCol + 6)
c = GetData(sheet, iRow, iCol + 5)
If isEmptyValue(sName) Then
iSkipCounter = iSkipCounter + 1
If isToEnd(iSkipCounter) Then
Exit Do
End If
Else
iSkipCounter = 0
s = s & sExpectedValue & transferSeperator(c)
End If
iRow = iRow + 1
Loop
makeMessage = s
End Function
'to transfer seperator
Public Function transferSeperator(ByVal c As String) As String
Dim s As String
If VBA.UCase(VBA.Trim(c)) = "TAB" Then
s = VBA.vbTab
ElseIf VBA.UCase(VBA.Trim(c)) = "SPACE" Then
s = VBA.Space(1)
Else
s = ""
End If
transferSeperator = s
End Function
'to determine whether it is empty
Public Function isEmptyValue(ByVal sValue As String) As Boolean
Dim ok As Boolean
If VBA.Trim(sValue) = "" Then
ok = True
Else
ok = False
End If
isEmptyValue = ok
End Function
'to determine whether it is time to end the process
Public Function isToEnd(ByVal iSkipCounter As Integer) As Boolean
Dim ok As Boolean
If iSkipCounter > MAX_EMPTY_ROW Then
ok = True
Else
ok = False
End If
isToEnd = ok
End Function
总归一句话:VBA后台可以做,但是你要把VBA放到前台,你需要写一个宏,然后给这个宏加一个按钮,它就跑到前台界面来了。如果你不会写程序,可以录制一个宏,然后学习一下。虽然有一定难度,但是会让你受益非浅。 |
|