Vba 将合并的单元格视为一个
我使用excel中的VBA代码将选定区域导出到文本文件,但当我使用合并单元格(合并行)时,在导出中会添加空行。如何使代码将合并的单元格视为一个Vba 将合并的单元格视为一个,vba,excel,Vba,Excel,我使用excel中的VBA代码将选定区域导出到文本文件,但当我使用合并单元格(合并行)时,在导出中会添加空行。如何使代码将合并的单元格视为一个 Sub writeCSV(ByVal thisRange As Range, ByVal filePath As String, Optional ByVal fileAppend As Boolean = False) Dim cLoop As Long, rLoop As Long Dim ff As Long, strRow As String
Sub writeCSV(ByVal thisRange As Range, ByVal filePath As String, Optional ByVal fileAppend As Boolean = False)
Dim cLoop As Long, rLoop As Long
Dim ff As Long, strRow As String
ff = FreeFile
If fileAppend Then
Open filePath For Append As #ff
Else
Open filePath For Output As #ff
End If
For rLoop = 1 To thisRange.Rows.Count
strRow = ""
For cLoop = 1 To thisRange.Columns.Count
If cLoop > 1 Then strRow = strRow & ","
strRow = strRow & thisRange.Cells(rLoop, cLoop).Value
Next 'cLoop
Print #ff, strRow
Next 'rLoop
Close #ff
End Sub
Sub Wri()
Dim myrng As Range
Dim Cell As Range
On Error Resume Next
Set myrng = Application.InputBox("Select range", Type:=8)
On Error GoTo 0
If myrng Is Nothing Then
MsgBox "No cells selected"
Exit Sub
Else
writeCSV myrng, "C:\Users\HP\Documents\fil.txt", True
End If
End Sub
很难想象您希望它的具体表现:如果只合并一行的一部分,或者合并多行的一部分,该怎么办。取消合并,然后重新合并?是否可以使用所选范围内最顶端单元格的单元格地址而忽略其他单元格地址,其他单元格地址都将是合并的一部分,并且将为0?