Hi,
I have a dataset with several different columns - each column has a title (e.g. "C2") and each column has values in it. I am trying to write a VBA code so I can type in a value in B33, the code reads through the column to see if it's there and if it is, it copies in the column title below. I'd like to repeat this through all the columns so I have a list of the column titles which include the value I write in B33.
Any ideas? This is what I originally had, but needs tweaking with a loop and also I want all Column Names which get picked up to appear in a list. Thanks so much!!!
Sub Check()
'clear previous
Range("B35:B500").Clear
'Making insert text, answer is IF statement 1 or 0
Dim insert As String, answer As Integer
insert= Range("C2").Value
'Check if it's there
answer = WorksheetFunction.CountIf(Range("C:C"), Range("B33"))
' If statement and Then
If answer = 1 Then
Range("B35").Value = insert
End If
'repeating for others
insert = Range("D2").Value
answer = WorksheetFunction.CountIf(Range("D:D"), Range("B33"))
' If statement and Then
If answer = 1 Then
Range("B36").Value = insert
End If
......
End Sub
I have a dataset with several different columns - each column has a title (e.g. "C2") and each column has values in it. I am trying to write a VBA code so I can type in a value in B33, the code reads through the column to see if it's there and if it is, it copies in the column title below. I'd like to repeat this through all the columns so I have a list of the column titles which include the value I write in B33.
Any ideas? This is what I originally had, but needs tweaking with a loop and also I want all Column Names which get picked up to appear in a list. Thanks so much!!!
Sub Check()
'clear previous
Range("B35:B500").Clear
'Making insert text, answer is IF statement 1 or 0
Dim insert As String, answer As Integer
insert= Range("C2").Value
'Check if it's there
answer = WorksheetFunction.CountIf(Range("C:C"), Range("B33"))
' If statement and Then
If answer = 1 Then
Range("B35").Value = insert
End If
'repeating for others
insert = Range("D2").Value
answer = WorksheetFunction.CountIf(Range("D:D"), Range("B33"))
' If statement and Then
If answer = 1 Then
Range("B36").Value = insert
End If
......
End Sub