[英]Cross-reference in table
我是VBA的乞討人,正在尋找一種解決方案來檢查表中的內容。 我想創建一個函數,該函數僅在標題列(范圍)中的單元格等於某個值時才告訴某個列(范圍)中的單元格是否不為空。 我嘗試將isempty和vlookup結合使用,但沒有用。 我希望描述清楚,無論如何,我都會附上一張簡化的表格。 先感謝您! 在此處輸入圖片說明
不確定我是否100%理解了您的問題,但讓我從我認為的理解開始,並從以下內容開始:
Sub isitEmpty()
With Sheets("Sheet1")
If IsEmpty(.Range("B1:E2")).Value Then
'do something
Else
'do something
End If
End With
End Sub
如果單元格為空/不為空,該怎么辦?
以下代碼在以下假設下工作:
Cell A4
開始, Project Type
列在Column A
列中 A,B,C,D
類別可能有所不同,但在Row 3
始終會有標題 您希望參與的Project Type
為Y
,列在標題為A,B,C,D
的最后一列之后。 因此,根據您的圖片,其Column F
Sub Demo() Dim ws As Worksheet Dim lRProject As Long, lRMatch As Long, lastColumn As Long, i As Long Dim rngProject As Range, celPro As Range, rngMatch As Range, celMatch As Range Set ws = ThisWorkbook.Sheets("Sheet5") 'change to your sheet With ws lastColumn = .Cells(3, Columns.count).End(xlToLeft).Column 'gives last column with A,B,C,D lRProject = .Cells(.Rows.count, "A").End(xlUp).Row 'last row in Column A lRMatch = .Cells(.Rows.count, lastColumn + 1).End(xlUp).Row 'last row in Column F Set rngMatch = .Range(.Cells(1, lastColumn + 1), .Cells(lRMatch, lastColumn + 1)) Set rngProject = .Range("A4:A" & lRProject) For Each celMatch In rngMatch For Each celPro In rngProject For i = 2 To lastColumn If celPro.Value = celMatch Then If .Cells(celPro.Row, i) = "X" Then .Cells(celMatch.Row, i) = "Y" End If End If Next i Next celPro Next celMatch End With End Sub
參見圖片以供參考。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.