Howard는 워크 시트에서 주어진 너비의 모든 열을 찾아야합니다. 예를 들어 너비가 3.6 인 열을 알아야합니다.

이것은 매크로를 사용하여 수행 할 수 있습니다. 매크로에서 액세스 할 수있는 속성 중 하나는 각 열의 너비입니다. 이는 다음과 같은 방식으로 열을 단계별로 살펴보고 원하는 너비 (3.6)에 대해 해당 너비를 확인할 수 있음을 의미합니다.

Sub ListColumns()

Dim dColWidth As Double     Dim sMsg As String     Dim x As Integer

dColWidth = 3.6     sMsg = ""

For x = 1 To ActiveSheet.Columns.Count         If Columns(x).ColumnWidth = dColWidth Then             sMsg = sMsg & vbCrLf & x         End If     Next     If sMsg = "" Then         sMsg = "There are no columns with" & _           vbCrLf & "a width of " & dColWidth     Else         sMsg = "The following columns have" & _           vbCrLf & "a width of " & dColWidth & _           ":" & vbCrLf & sMsg     End If     MsgBox sMsg End Sub

이 매크로는 원하는 너비와 일치하는 열을 나열하는 메시지 상자를 표시합니다. 몇 가지 간단한 변경으로 매크로를 더욱 강력하게 만들 수 있습니다. 예를 들어, 다음 예제는 사용자에게 열 너비를 입력하라는 메시지를 표시하고 일치 항목 수를 계산하며 워크 시트가 R1C1 참조 모드를 사용중인 경우에도 보상합니다.

Sub Find_ColumnWidth()

Dim Col As Integer          ' Column (loop variable)

Dim ColsFound As Integer    ' Columns Found Count     Dim Desired_Width As Double ' Column Width To Find     Dim OutStr As String        ' Output String     Dim Title As String         ' Msgbox Title     Dim I As Integer     Dim S As String

' Find out column width wanted     S = InputBox("Enter ColumnWidth to find ?", _       " Find ColumnWidth on " & ActiveSheet.Name)

Desired_Width = Val(S)

If Desired_Width = 0 Then Exit Sub

' Initialize Columns Found Count and Output String     ColsFound = 0     OutStr = ""



For Col = 1 To ActiveSheet.Columns.Count         If Columns(Col).ColumnWidth = Desired_Width Then             ColsFound = ColsFound + 1

If Application.ReferenceStyle = 1 Then                 ' Using "A1" format                 S = Cells(1, Col).Address(ReferenceStyle:=xlA1)

S = Mid(S, 2, Len(S) - 3)

Else                 ' Using "R1C1" format                 S = Trim(Str(Col))

End If             OutStr = OutStr & S & vbCrLf         End If     Next

' Construct MsgBox Title string     Title = "Width=" & Desired_Width _       & " on " & ColsFound & " column" _       & Left("s", - (ColsFound > 1)) & " "



If ColsFound = 0 Then         OutStr = "No matches found"

End If

MsgBox OutStr, vbOKOnly, Title End Sub

_ 참고 : _

이 페이지 (또는 ExcelTips 사이트의 다른 페이지)에 설명 된 매크로를 사용하는 방법을 알고 싶다면 유용한 정보가 포함 된 특별 페이지를 준비했습니다.

link : / excelribbon-ExcelTipsMacros [새 브라우저 탭에서 특별 페이지를 열려면 여기를 클릭하세요].

_ExcelTips_는 비용 효율적인 Microsoft Excel 교육을위한 소스입니다.

이 팁 (3827)은 Microsoft Excel 97, 2000, 2002 및 2003에 적용됩니다. 여기에서 Excel (Excel 2007 이상)의 리본 인터페이스에 대한이 팁 버전을 찾을 수 있습니다.

link : / excelribbon-Finding_Columns_of_a_Certain_Width [특정 너비의 열 찾기].