주어진 열 머리글 집합이 있고 열 머리글 이름 만 알고 있다고 가정 해보십시오. 방금 열 이름을 검색하고 싶습니다. 예를 들어 "텍스트"라는 열 이름을 찾고 셀 A에 있습니다. 그런 다음 결과를 A로 지정하고 싶지만 아무에게도 도움을 줄 수는 없습니다. 여기 알려진 열 헤더 이름을 사용하여 열 값을 얻는 방법
내 코드입니다Sub searchHeader()
columnNamesRow = 1 ' or whichever row your names are in
nameToSearch = "Text" ' or whatever name you want to search for
columnToUse = 0
lastUsedColumn = Worksheets("Sheet1").Cells(1, Worksheets("Sheet1").Columns.Count).End(xlToLeft).Column
For col = 1 To lastUsedColumn
If Worksheets("Sheet1").Cells(columnNamesRow, col).Value = nameToSearch Then
columnToUse = col
End If
Next col
If columnToUse > 0 Then
' found the column you wanted, do your thing here using "columnToUse" as the column index
MsgBox columnToUse
End If
End Sub
여기 [Function] (http://stackoverflow.com/questions/12796973/function-to-convert-column-number-to-letter)를 사용하면 도움이되기를 바랍니다. – newguy
감사합니다. –