gpt4 book ai didi

vba - 将变量设置为标题文本列

转载 作者:行者123 更新时间:2023-12-04 21:34:03 25 4
gpt4 key购买 nike

我有一本从未以相同格式收到的工作簿。为了防止人工干预,我需要捕获文本 employee 的列例如,如果文本在 O 列中 - 我将执行以下操作,但我需要 Cells(i,"O")根据包含文本 employee 的单元格进行更改

Sub DoThis()
Application.ScreenUpdating = False
Dim i As Long
For i = Range("A" & Rows.Count).End(3).Row To 2 Step -1
If Not IsEmpty(Cells(i, "O").Value) Then
'stuff here
End If
Next i
End Sub

最佳答案

您可以使用 Find方法并获取 employee 的单元格的列被发现在 Cells 中使用:

Option Explicit

Sub DoThis()

Dim i As Long
Dim lngCol As Long

With Worksheets("Sheet1") '<-- change to your sheet
lngCol = .Rows(1).Find("employee").Column '<-- assumes header in Row 1
For i = .Range("A" & .Rows.Count).End(3).Row To 2 Step -1
If Not IsEmpty(.Cells(i, lngCol).Value) Then
'stuff here
End If
Next i
End With

End Sub

关于vba - 将变量设置为标题文本列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43635026/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com