发布网友 发布时间:2022-04-23 09:58
共3个回答
热心网友 时间:2023-10-10 12:25
没有具体附件,感觉楼主描述做了模拟
详见代码及截图:
Sub 按钮1_Click()
Set d = CreateObject("scripting.dictionary")
Application.ScreenUpdating = False
arr = Range("bp1:ee" & ActiveSheet.UsedRange.Rows.Count)
For j = 1 To ActiveSheet.UsedRange.Rows.Count
d.RemoveAll
For i = 1 To UBound(arr, 2)
If InStr(arr(j, i), "余") > 0 Then
brr = Split(arr(j, i), "余")
d(Val(brr(1))) = Val(brr(1))
End If
Next i
x = 0
For i = WorksheetFunction.Min(d.keys) To WorksheetFunction.Max(d.keys)
If d.exists(i) Then
x = x + 1
Cells(j, x) = Chr(69 + i)
End If
Next i
Next j
Application.ScreenUpdating = True
End Sub
热心网友 时间:2023-10-10 12:25
先把条件循环写入字典。例如2余0对应字母E。
可以循环bq列到ee列号,嵌套循环行号。
循环到相应的行列号时,判断行列号的值是否在字典中存在,存在则提取相应的值写入相应位置。
热心网友 时间:2023-10-10 12:26
For i = 1 To 5
For j = 7 To 9
If Cells(i, j).Value Like "2余1" Then
Cells(i, 1).Value = "F"
Else
If Cells(i, j).Value Like "3余1" Then
Cells(i, 2).Value = "F"
End If
Next j
Next i
5代表5行数据:从1开始
7代表bp的列数
9代表ee的列数