excel - Excel VBA用循环连接单元格
问题描述
我下面的代码从它上面的单元格中按顺序生成下一个数字,在双击时在 C 列的最后一个空白单元格中。
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As
Boolean)
Dim lastrow As Long
lastrow = Cells(Cells.Rows.Count, "C").End(xlUp).Row + 1
If Not Intersect(Target, Range("C:C")) Is Nothing Then
If Target.Address = Cells(lastrow, "C").Address Then
Application.EnableEvents = False
Cancel = True
Cells(lastrow, "C") = Cells(lastrow - 1, "C") + 1
Application.EnableEvents = True
End If
End If
End Sub
我想做的是在 D 列的同一行中为单元格添加一个简单的连接,在新生成的数字前面加上字母“TLD”。我在这个网站上尝试了几个例子,但我没有取得太大的成功,因为我不太清楚如何将它包含在这个代码中,或者确实应该包含它?
因此,例如,单元格 C2 = 300000 单元格 D2 应读取 TLD300000。我不想使用公式,因为我不知道随着时间的推移将使用多少行。有任何想法吗?谢谢保罗
解决方案
添加一行
….
Cells(lastrow, "C") = Cells(lastrow - 1, "C") + 1
Cells(lastrow, "D") = "TLD" & Cells(lastrow - 1, "C") '<--- added line
推荐阅读
- json - 为什么通过属性访问字段的行为不像直接访问字段?
- python - Pygame:为什么我不能画一个圆形精灵
- excel - Excel VBA,用于根据用户选择设置特定单元格值
- scala - SCIO 用 scio parquet 读取 parquet 文件,未找到生成的案例类
- excel - 将数据透视表添加到顺序工作表
- c - 如何在 scanf 函数中使用编辑转换代码来停止在特定单词处扫描字符串
- pandas - 使用我有条件标记的值创建新列
- xamarin - Xamarin 使用框架创建圆形图像
- c - 如何忽略所有小于第一个参数值的输入,然后传递给数组/函数?(C语言)
- arrays - Ruby 将数组拆分为仅包含不同值的子数组