메인 컨텐츠로 가기

열을 행으로 바꾸고 새 행을 삽입하여 Excel에서 데이터를 채우는 방법은 무엇입니까?

이 기사에서는 열을 행으로 바꾸고 새 행을 삽입하여 아래 스크린 샷과 같이 데이터를 채우는 VBA 코드를 소개합니다.이 작업에 관심이 있다면 아래로 이동하여 자세한 내용을 확인하십시오.
문서 삽입 행 1 바꾸기

VBA로 행 전치 및 삽입


화살표 블루 오른쪽 거품 VBA로 행 전치 및 삽입

범위를 바꾸고 동일한 데이터를 채우기 위해 행을 삽입하는 직접적인 방법은 없지만 여기서는 VBA 코드를 도입하여이 작업을 빠르게 해결할 수 있습니다.

1. 프레스 Alt + F11 여는 열쇠 응용 프로그램 용 Microsoft Visual Basic 창.

2. 클릭 끼워 넣다 > 모듈을 클릭하고 VBA 코드 아래에 모듈 창에 붙여 넣습니다. 스크린 샷보기 :

VBA : 행을 바꾸고 삽입합니다.

 Sub TransposeInsertRows()
'UpdatebyExtendoffice20161125
    Dim xRg As Range
    Dim i As Long, j As Long, k As Long
    Dim x As Long, y As Long
    Set xRg = Application.InputBox _
    (Prompt:="Range Selection...", _
    Title:="Kutools For Excel", Type:=8)
    Application.ScreenUpdating = False
    x = xRg(1, 1).Column + 2
    y = xRg(1, xRg.Columns.Count).Column
    For i = xRg(xRg.Rows.Count, 1).Row To xRg(1, 1).Row Step -1
        If Cells(i, x) <> "" And Cells(i, x + 1) <> "" Then
            k = Cells(i, x - 2).End(xlToRight).Column
            If k > y Then k = y
            For j = k To x + 1 Step -1
                Cells(i + 1, 1).EntireRow.Insert
                With Cells(i + 1, x - 2)
                    .Value = .Offset(-1, 0)
                    .Offset(0, 1) = .Offset(-1, 1)
                    .Offset(0, 2) = Cells(i, j)
                End With
                Cells(i, j).ClearContents
            Next j
        End If
    Next i
    Application.ScreenUpdating = True
End Sub

 

문서 삽입 행 2 바꾸기

3. 프레스 F5 키를 눌러 코드를 실행 한 다음 전치하려는 데이터 범위를 선택하고 팝업 대화 상자에 행을 삽입합니다. 스크린 샷보기 :
문서 삽입 행 3 바꾸기

4. 클릭 OK. 그리고 선택된 범위는 아래 스크린 샷과 같이 변환되었습니다.
문서 삽입 행 4 바꾸기

주의 사항: 코드를 실행하기 전에 원본 데이터의 복사본을 저장하는 것이 좋습니다.

팁.크로스 테이블을 목록 테이블로 또는 그 반대로 빠르게 바꾸려면 Excel 용 Kutools를 사용하십시오. 테이블 차원 전치 다음 스크린 샷에 표시된대로. 30 일 안에 제한없이 모든 기능을 사용할 수 있습니다. 지금 다운로드하여 무료 평가판을 받으십시오.

doc 크로스를 목록으로 조옮김

최고의 사무 생산성 도구

🤖 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 (8)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Compiler errorSyntax Error
Dim xRg As Range
Dim i As Long, j As Long, k As Long
Dim x As Long, y As Long

This comment was minimized by the moderator on the site
The above code works great. It keeps the first two columns. How would I change the code so that it only keeps the first column?
This comment was minimized by the moderator on the site
How can I transpose the data every two cells

The initial exercise is:


Class1 | Name | Nancy | Judy | Lily | Daniel
Class2 | Name | Bruce | Uee | Perter | Daniel
Class3 | Name | kate | Kelly | Wenddy | Daniel

and I need it to look like this:

Class1 | Name | Nancy | Judy
Class1 | Name | Lily | Daniel
Class 2 | Name | Bruce | Uee
Class 2 | Name | Perter | Daniel
Class3 | Name | kate | Kelly
Class3 | Name | Wenddy | Daniel
This comment was minimized by the moderator on the site
how can I make data 3 and 4 remain in the same column:


the initial exercise is:

Class1 | Name | Nancy | Judy | Lily | Daniel
Class2 | Name | Bruce | Uee | Perter | Daniel
Class3 | Name | kate | Kelly | Wenddy | Daniel

I need to transpose it like this

Class1 | Name | Nancy | Judy
Class1 | Name | Lily | Daniel
Class 2 | Name | Bruce | Uee
Class 2 | Name | Perter | Daniel
Class3 | Name | kate | Kelly
Class3 | Name | Wenddy | Daniel
This comment was minimized by the moderator on the site
how would i change the VBA code so that it will keep more of the columns the same? for example instead of the first two columns staying the same it will be the first 4?
This comment was minimized by the moderator on the site
I am not sure, may be you can try to change x = xRg(1, 1).Column + 2 to x = xRg(1, 1).Column + 4.
This comment was minimized by the moderator on the site
If my cross table's informations come from formulas, those formulas don't always follow when the macro is applied. How could I fix this to make sure that the formulas are kept in the cells?
This comment was minimized by the moderator on the site
Hi, thank u for ur message. For solving your problem, you can apply Kutools' Convert Formula to Text before you running the macro, then after transposing thetable, apply Kutools' Convert Text to Formula. Please Let me know if it works. Thank u.
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations