[英]How can I compare two columns, determine the value of column 2 from the value in column 1, in VBA, without adding a formula into column 2
我有一個第 1 列,如果它有一個值,我想將第 2 列的值更改為“DEV”。 我不想將公式添加到第 2 列。我希望這樣的事情會起作用:
If [@Defect] (column 1) is <> "" Then [@Status] = "DEV"
或者
If ActiveSheet.ListObjects(Table1).ListColumns("Defects").DataBodyRange <> "" Then
ActiveSheet.ListObjects(Table1).ListColumns("Status").DataBodyRange = "DEV"
我想參考列名/標題以根據需要重新排序數據。 但是,我沒有看到這種類型的任何示例,並且我知道語法不正確。
這段代碼應該可以幫助你確定你的列在哪里(我對我的一些報告做了非常相似的事情,它對我很有效)
Sub gGetCols()
Dim DefectCol As Long
Dim StatusCol As Long
Dim FoundAll As Long
Dim xlCell As Range
FoundAll = 0
Set xlCell = Range("A1")
Do Until xlCell = ""
Select Case xlCell
Case "Defect"
DefectCol = xlCell.Column
FoundAll = FoundAll + 1
Case "Status"
StatusCol = xlCell.Column
FoundAll = FoundAll + 1
End Select
If FoundAll = 2 Then Exit Do
Set xlCell = xlCell.Offset(0, 1)
Loop
End Sub
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.