Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vba 将合并的单元格视为一个_Vba_Excel - Fatal编程技术网

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

我使用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

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?