列中每个单元格的循环过程

时间:2018-07-18 10:27:46

标签: excel vba excel-vba

我创建了以下代码,该代码将执行一些筛选任务,然后根据级联键进行valookup。 您能帮我在Y栏上为每个单元格循环编码吗? 该代码适用于单元格Y3。

这是我的代码:

ipcRenderer.on('printImage', (event, arg) => {
    var divImage = document.getElementById(idDiv)
    if (divImage !== null && divImage !== undefined)
        divImage.getElementsByTagName('img')[0].src = arg.pathImage
})

2 个答案:

答案 0 :(得分:0)

您可以使用For ... Next遍历Y列中的每个单元格。例如,这遍历单元格Y1到Y100:

'[...]

Dim i as Long
Dim first_row As Long
Dim last_row As Long

first_row = 1
last_row = 100

For i = first_row To last_row
  e_name = Range("A" & i)
  LValue = "Your" & e_name
  Segment = Application.WorksheetFunction.VLookup(LValue, Sheets("Temp").Range("C:N"), 12, True)
  Range("Y" & i).Value = Segment
Next i

'[...]

答案 1 :(得分:0)

这可以做到。它将继续从A3向下移动,直到没有更多数据,然后写入Y列的同一行。

将以下内容粘贴到底部,替换ActiveSheet.Paste之后的所有内容:

Dim e_name As String
Dim LValue As String
Dim c As Range

With Sheets("Exception Data")

    For Each c In .Range("A3", "A" & .Cells(.Rows.Count, "A").End(xlUp).Row)
        e_name = c.Value
        LValue = "Your" & e_name
        Segment = Application.WorksheetFunction.VLookup(LValue, Sheets("Temp").Range("C:N"), 12, True)
        c.Offset(0, 24).Value = Segment ' write to column A, offset by 24 to the right - column Y
    Next

End With

Application.DisplayAlerts = False
Sheets("Temp").Delete
Application.DisplayAlerts = False