我对VBA不是很有经验,这也是我第一次写,但我还是尝试了一下。我想我从我尝试做的事情开始,在开始的时候,我为,,x,,标记设置了一些条件。我写了一个代码,当它从列F中找到任何值时,将,,x,,写入列AN。
之后,我希望,,,x,,在每个匹配中只出现一次(这样就不会有来自F列的重复)。
那起作用了,但那不是目标,那是我唯一能达到的目标。
代码完成后,我会解释我必须实现的目标
目前代码:
Sub mark_x()
Dim lastRow As Long
Dim values As New Collection
lastRow = ActiveSheet.Cells(Rows.Count, "F").End(xlUp).Row
For i = 2 To lastRow
If Not IsEmpty(Cells(i, "F")) Then
On Error Resume Next
values.Add Cells(i, "F").Value, CStr(Cells(i, "F").Value)
If Err.Number <> 0 Then
Cells(i, "AN").Value = "x"
End If
On Error GoTo 0
End If
Next i
End Sub
所以我在这里描述我想要达到的目标:
我有一个excel文件,其中我的主要重点是列C,E,F和AN。
C -项目编号,E -国家,F -供应商和AN - X标记
在以下情况下,我需要在AN列中有X标记:-条件是AN中的X对于物料- C、供应商- F和国家/地区- E只能出现一次,例如
总会有相同的国家:斯洛伐克、捷克、罗马尼亚、PL、HR、保加利亚、德国
- 也有多行,我只做了几个屏幕
- 我试着把它做对,但我做不到
对不起,如果我写的帖子在错误的方式。
2条答案
按热度按时间hrirmatl1#
大家好欢迎来到Stack Overflow
我相信你的问题问对了。至少你说清楚了期望的产出是什么。
所以你要做的是:为那些给定值的并集不同的行设置一个值“x”。下面是我的解决方案代码(你可以找到一些注解,这样你就可以理解一切):
虽然我已经尝试尽可能地使其适应您的需要,但您可能需要进行一些小的更改才能使其适合您的数据。希望这对您有所帮助
ua4mk5z42#
标记第一行(多列)