메인 컨텐츠로 가기

Excel에서 헤더 값을 기반으로 전체 열을 삭제하는 방법은 무엇입니까?

대부분의 경우 Excel의 헤더 값을 기반으로 전체 열을 삭제해야 할 수 있습니다. 예를 들어 헤더에 "old"값이 포함 된 모든 열을 삭제해야합니다. 이 튜토리얼에서는 헤더 값을 기반으로 전체 열을 삭제하는 방법을 자세히 보여줍니다.

VBA 코드로 헤더 값을 기반으로 전체 열 삭제
Excel 용 Kutools를 사용하여 헤더 값을 기반으로 전체 열 삭제


VBA 코드로 헤더 값을 기반으로 전체 열 삭제

VBA 코드로 헤더 값을 기반으로 전체 열을 삭제할 수 있습니다. 다음과 같이하십시오.

1. 프레스 다른 + F11 동시에 열려면 키 Microsoft Visual Basic 응용 프로그램 창.

2. 에서 Microsoft Visual Basic 응용 프로그램 창을 클릭합니다 끼워 넣다 > 모듈. 그런 다음 아래 코드를 복사하여 모듈 창에 붙여 넣습니다.

VBA 코드 : 헤더 값을 기준으로 전체 열 삭제

Sub DeleteSpecifcColumn()
	Set MR = Range("A1:D1")
	For Each cell In MR
		If cell.Value = "old" Then cell.EntireColumn.Delete
	Next
End Sub

노트:

1) 코드에서 "낡은”는 전체 열을 삭제할 기준이되는 헤더 값입니다. 헤더 값을 수동으로 변경하십시오. 과 A1 : D1 사용하려는 열 범위입니다.
2) 이 코드는 대소문자를 구분합니다.

3. 누르세요 F5 키를 눌러 코드를 실행하면 헤더가 지정된 텍스트와 동일한 전체 열이 즉시 삭제됩니다.


Excel 용 Kutools를 사용하여 헤더 값을 기반으로 전체 열 삭제

Excel 용 Kutools특정 셀 선택 유틸리티를 사용하면 먼저 특정 헤더 값을 포함하는 모든 열을 쉽게 선택한 다음 선택한 열을 한 번에 삭제할 수 있습니다. 다음과 같이하십시오.

신청하기 전에 Excel 용 Kutools, 제발 먼저 다운로드하여 설치하십시오..

1. 삭제해야하는 열이 포함 된 범위를 선택한 다음 쿠툴 > 선택 > 특정 셀 선택. 스크린 샷보기 :

2. 에서 특정 셀 선택 대화 상자에서 전체 열 에서 옵션 선택 유형 섹션 및 특정 유형 드롭 다운 목록에서 같음 옵션을 선택하고 다음 상자에 헤더 값을 입력하십시오. 마지막으로 OK 단추. 스크린 샷보기 :

3. 을 클릭합니다 OK 다른 팝업 대화 상자에서 버튼을 누르면 지정된 헤더 값이 포함 된 열이 즉시 선택됩니다.

4. 선택한 열의 열 머리글을 마우스 오른쪽 단추로 클릭 한 다음 . 오른쪽 클릭 메뉴에서. 그런 다음 선택한 모든 열이 한 번에 삭제됩니다.

  이 유틸리티의 무료 평가판 (30 일)을 받으려면 그것을 다운로드하려면 클릭하십시오을 클릭 한 다음 위 단계에 따라 작업 적용으로 이동합니다.

최고의 사무 생산성 도구

🤖 Kutools AI 보좌관: 다음을 기반으로 데이터 분석을 혁신합니다. 지능형 실행   |  코드 생성  |  사용자 정의 수식 만들기  |  데이터 분석 및 차트 생성  |  Kutools 기능 호출...
인기 기능: 중복 항목 찾기, 강조 표시 또는 식별   |  빈 행 삭제   |  데이터 손실 없이 열이나 셀 결합   |   수식없이 반올림 ...
슈퍼 조회: 다중 기준 VLookup    다중 값 VLookup  |   여러 시트에 걸친 VLookup   |   퍼지 조회 ....
고급 드롭다운 목록: 드롭다운 목록을 빠르게 생성   |  종속 드롭다운 목록   |  다중 선택 드롭 다운 목록 ....
열 관리자: 특정 개수의 열 추가  |  열 이동  |  Toggle 숨겨진 열의 가시성 상태  |  범위 및 열 비교 ...
특색 지어진 특징: 그리드 포커스   |  디자인보기   |   큰 수식 바    통합 문서 및 시트 관리자   |  리소스 라이브러리 (자동 텍스트)   |  날짜 선택기   |  워크 시트 결합   |  셀 암호화/해독    목록으로 이메일 보내기   |  슈퍼 필터   |   특수 필터 (굵게/기울임꼴/취소선 필터링...) ...
상위 15개 도구 세트12 본문 도구 (텍스트 추가, 문자 제거,...)   |   50+ 거래차트 유형 (Gantt 차트,...)   |   40+ 실용 방식 (생일을 기준으로 나이 계산,...)   |   19 삽입 도구 (QR 코드 삽입, 경로에서 그림 삽입,...)   |   12 매출 상승 도구 (숫자를 단어로, 환율,...)   |   7 병합 및 분할 도구 (고급 결합 행, 셀 분할,...)   |   ... 그리고 더

Excel용 Kutools로 Excel 기술을 강화하고 이전과는 전혀 다른 효율성을 경험해 보세요. Excel용 Kutools는 생산성을 높이고 시간을 절약하기 위해 300개 이상의 고급 기능을 제공합니다.  가장 필요한 기능을 얻으려면 여기를 클릭하십시오...

상품 설명


Office Tab은 Office에 탭 인터페이스를 제공하여 작업을 훨씬 쉽게 만듭니다.

  • Word, Excel, PowerPoint에서 탭 편집 및 읽기 사용, Publisher, Access, Visio 및 Project.
  • 새 창이 아닌 동일한 창의 새 탭에서 여러 문서를 열고 만듭니다.
  • 생산성을 50% 높이고 매일 수백 번의 마우스 클릭을 줄입니다!
Comments (13)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Hi, I need to delete a load of columns containing # in the headings - my understanding of VBA is very limited and the report has about 60 columns. The # is not always in the same location in each heading, so I need to identify any columns with the # in the heading and remove those columns. Is anyone able to guide me on this please?

I also need to split the report into 3 sections - the data runs across the worksheet (ie column A - H is Sales invoices; column I-Z is Purchase invoices and column AA-AG is Payments - each of these need to go onto a seperate worksheet - it is very labour intensive doing this manually so I am hoping someone can help me in VBA with this one as well.

Thanks
This comment was minimized by the moderator on the site
Hola, tengo una hoja de excel con varios datos, digamos 4 columnas y 12 filas, me gustaría poder imprimir cada fila en un folio separado en una plantilla, es decir, tenemos una hoja con varios nombres y apellidos y teléfono, quiero imprimir tantas páginas como filas tenga la hoja de excel, he inte tado varias cosas pero no encuentro la forma. Gracias de antemano
This comment was minimized by the moderator on the site
Hi,
If you want to print each row in a separate page in the worksheet, here is a suggestion that you insert page breaks every 1 row and then print them.
Methods provided in this article may do you a favor. Please have a try. Thank you.
How To Insert Page Break Every X Rows In Excel?[/url]
https://www.extendoffice.com/documents/excel/1774-excel-insert-page-break-every-row.html
This comment was minimized by the moderator on the site
The VBA example states that the code will delete all columns whose headers CONTAIN "old." That is not the case. The = operator will only delete exact matches. You need to use the LIKE operator with a wildcard.
Fixed code:Sub DeleteSpecifcColumn()
Set MR = Range("A1:D1")
For Each cell In MR
If cell.Value LIKE "old*" Then cell.EntireColumn.Delete
Next
End Sub

This comment was minimized by the moderator on the site
Hi,Thank you for your correction and sharing. 
This comment was minimized by the moderator on the site
Hi, is it possible to do this with multiple column names?
This comment was minimized by the moderator on the site
What if the headers are starting from 4th row
This comment was minimized by the moderator on the site
Hi Mark,
Try the below code. In the eighth line, please enclose each column name with double quotes and separate them by comma. Hope I can help. Thank you.

Sub DeleteSpecifcColumn()

Dim xFNum, xFFNum, xCount As Integer

Dim xStr As String

Dim xArrName As Variant

Dim MR, xRg As Range

On Error Resume Next

Set MR = Range("A1:N1")

xArrName = Array("old", "new", "get") 'enclose each column name with double quotes and separate them by comma

xCount = MR.Count

xStr = xArrName(xFNum)

For xFFNum = xCount To 1 Step -1

Set xRg = Cells(1, xFFNum)

For xFNum = 0 To UBound(xArrName)

xStr = xArrName(xFNum)

If xRg.Value = xStr Then xRg.EntireColumn.Delete

Next xFNum

Next

End Sub
This comment was minimized by the moderator on the site
I think line 12 needs to be changed to get the code to work. Original line 12 "Set xRg = Cells(1, xFFNum)" modified line 12 "Set xRg = MR(1, xFFNum)"
Sub DeleteSpecifcColumn()
Dim xFNum, xFFNum, xCount As Integer
Dim xStr As String
Dim xArrName As Variant
Dim MR, xRg As Range
On Error Resume Next
Set MR = Range("A1:N1")
xArrName = Array("old", "new", "get") 'enclose each column name with double quotes and separate them by comma
xCount = MR.Count
xStr = xArrName(xFNum)
For xFFNum = xCount To 1 Step -1
Set xRg = MR(1, xFFNum)
For xFNum = 0 To UBound(xArrName)
xStr = xArrName(xFNum)
If xRg.Value = xStr Then xRg.EntireColumn.Delete
Next xFNum
Next
End Sub
This comment was minimized by the moderator on the site
Hey! This works well until you have two contiguous columns with the same header. Say your range is A1:A5, and A2 and A3 have the header 'old'. It will delete A2, but then the A3 will move to the place A2 used to occupy, and the code will skip it, as it will be looking at the new A3, the next cell on its range.
This comment was minimized by the moderator on the site
Hi Elias,
As you mentioned, A2 and A3 have he same header "old". But they are in the same column, after applying the code, the whole column A will be removed immediately.
I am not sure I get your point. Would be nice if you could provide screenshot of what you are trying to do.
This comment was minimized by the moderator on the site
Sorry if this seems super basic but this is my first time trying vba. Using this how would I apply it to delete multiple column headers. I am actually trying to only keep certain header columns and delete the rest of a changing list.
This comment was minimized by the moderator on the site
In the first code just copy the 4th row and change the "old" into the second column name and it will work
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations