![](/img/trans.png)
[英]How to find a value in one column in another column and return cells in row where value was found
[英]How to find a cell value on another worksheet and place a value on another column for the row where the first value was found
(我承认我是vba的新手,所以如果这是一个愚蠢的问题我很抱歉 - 我也很抱歉任何英语错误)
一些背景:
我负责公司支持代理的活动时间表。 例如,他们的领导可以发送请求将其从计划中删除。 并且每个代理可以在同一天有多个请求。 (时间表是每天)
所以,我有两个电子表格,“请求”和“时间表”
在请求工作表上:我需要检查列的每种类型的请求(假期,休息日......)(“E”列)如果我发现此请求,我需要来自另一行的代理电子邮件(P列),在“计划”工作表(“A”列)上搜索此电子邮件,并在“AI”列上放置“1”(我必须报告每个请求的结果)
我一直有一个问题,主要是在“计划”工作表上找到代理并放置“1”,我已经尝试了其他代码,但这是我一直在努力的最后一个(工作同事已经过了使用“Do While”和“Find”)
(现在excel刚刚崩溃)
我尝试过的一些内容:
If wal.Cells(row, 5) = "Remove from the Schedule - Vacation" Then
'Application.WorksheetFunction.Match(wal.Cells(row, 16).Value, wsc.Range("A:A"), 0).row
wsc.Cells(Application.WorksheetFunction.Match(wal.Cells(row, 16).Value, wsc.Range("A:A"), 0).row, 35) = 1
和
ElseIf Cells(row, 5) = "Remove from the Schedule - Vacation" Then
row = Application.WorksheetFunction.Match(wal.Cells(row, 16), sc.Range("A:A"), 0)
wsc.Cells(row, 35) = 1
Set wal = Worksheets("Alterações")
Set wsc = Worksheets("Schedule")
i = 5
j = 41
Do While wal.Range("E" & i) <> 0
If wal.Range("E" & i) = "Remover do Schedule - Férias" Then
Set agent = wal.Range("P" & i).Find(wsc.Range("A" & j).Value).row
Range("AI" & agent) = 1
End If
Loop
看看下面的Find
示例
Sub demo()
Dim wal As Worksheet: Set wal = Worksheets("Alterações")
Dim wsc As Worksheet: Set wsc = Worksheets("Schedule")
Dim rng As Range, UserRow As Range
Dim UserEmail As String
With wal
Set rng = .Columns(5).Find("Remove from the Schedule - Vacation")
If Not rng Is Nothing Then
UserEmail = rng.Offset(0, 11).Value2
Debug.Print rng.Address, UserEmail
With wsc
Set UserRow = .Columns(1).Find(what:=UserEmail)
If Not UserRow Is Nothing Then
UserRow.Offset(0, Columns("AI").Column - UserRow.Column).Value2 = 1
End If
End With
End If
End With
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.