excel - 如何增加行的单元格值,但在列中重复它们?
问题描述
我有一段代码效果很好,但我想按列递增这些值。假设我在 AE 列中有 60 个单元格,所以我必须ID_1
在ID_60
col A、B...E 中。我的代码的工作方式B1
是ID_61
任何建议如何解决它?
编辑:更改变量名的代码:
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
Dim HeaderName As String
HeaderName = Join(Array("Country", "City", "X", "Y"))
Dim LastUsedCell As Range
Set LastUsedCell = Nothing
Set LastUsedCell = ws.UsedRange.Find("*", , , , xlByRows, xlPrevious)
If Not LastUsedCell Is Nothing Then
Dim HeaderRow As Range
Set HeaderRow = ws.Range(ws.Cells(1, 1), ws.Cells(1, ws.Cells.Columns.Count).End(xlToLeft))
Indeks = 0
For Each Header In HeaderRow
If InStr(1, HeaderName, Header.Value, vbTextCompare) = 0 Then
Dim RangeToAnonimize As Range
Set RangeToAnonimize = ws.Range(ws.Cells(2, Header.Column), ws.Cells(LastUsedCell.Row, Header.Column))
For Each cell In RangeToAnonimize
cell.Value2 = "ID_" & Indeks
Indeks = Indeks + 1
Next cell
End If
Next Header
End If
Next ws
End Sub
代码的作用:
但是,目的是一行应该具有相同的 ID。
解决方案
你Indeks = 0
应该在之前For Each cell
Indeks = 0
For Each cell In RangeToAnonimize
推荐阅读
- android - 根据 Android 中的微调器选择删除 Firebase 子项
- php - PHP:反序列化 Java 的 BigInteger
- kotlin - 实体的主构造函数中的非空关系
- sql - 如何转入生成的列?
- javascript - 淘汰赛中的hasfocus事件在第一次点击时不起作用
- python - 缩放并在 iPython 中为 matplotlib 绘图设置光标
- python - 如何将参数分组为程序帮助消息的部分
- php - 有人可以帮我清理/合并代码吗
- c++ - c ++释放包含自定义类的向量的内存
- javascript - 如何在jquery中使用accounting.js从表中获取总价格?