excel - 循环遍历 excel 单元格强制至少有 2 个活动单元格
问题描述
我正在尝试将单元格的内容以特定格式打印到文本文件中。除非我填写了至少 2 行,否则一切正常。如果我只有 1 行,它就会崩溃。有人可以帮我吗?非常感谢!下面的代码:
Sub exportBanners()
Dim FileName As String
FileName = ThisWorkbook.Path & "\MT_BANNERS_" & Format(Now, "ddmmyy-hhmmss") & ".txt"
Dim c As Range, r As Range
Dim output As String
Dim lRow As Long
Dim lCol As Long
lRow = Cells(Rows.Count, 1).End(xlUp).Row
For Each r In Range("A9:B9", Range("A9:B9").End(xlDown)).Rows
For Each c In r.Cells
output = output & "|" & c.Value
Next c
output = output & vbNewLine
Next r
Open FileName For Output As #1
Print #1, output
Close
MsgBox "MT BANNERS requested successfully!"
End Sub
解决方案
推荐阅读
- php - PHP 创建计划页面和结帐后页面
- vba - 包含范围的文本的 Excel 转换——数字到字母数字
- bash - Bash:错误报告流程突然将值从 1 更改为 0
- debian - 在 Beaglebone green 上交叉编译 debian
- python-3.x - python中一些简单列表和if语句的错误
- ios - 黑色导航栏覆盖集合视图标题中的图像视图
- java - 如何使用 Gradle 4.4 创建一个包含所有依赖项的 jar?
- python - 无法索引
- python - 从读取 csv 转换为 excel - pandas/python
- tfs - 将 Visio 文件附加到 TFS 2018 Wiki 页面