메인 컨텐츠로 가기

Excel에서 셀 값이 변경 될 때 매크로를 실행하는 방법은 무엇입니까?

일반적으로 Excel에서는 F5 키 또는 실행 버튼을 눌러 VBA 코드를 실행할 수 있습니다. 그러나 셀 값이 변경 될 때 특정 매크로 코드를 실행 해 본 적이 있습니까? 이 기사에서는 Excel에서이 작업을 처리하는 몇 가지 빠른 트릭을 소개합니다.

VBA 코드로 특정 셀 값이 변경 될 때 매크로 실행 또는 호출

VBA 코드를 사용하여 범위에서 셀 값이 변경 될 때 매크로 실행 또는 호출


화살표 블루 오른쪽 거품 VBA 코드로 특정 셀 값이 변경 될 때 매크로 실행 또는 호출

셀 값을 변경하여 매크로 코드를 실행하려면 다음 VBA 코드가 도움이 될 수 있습니다. 다음과 같이하십시오.

1. 셀 값이 변경되면 매크로를 실행할 시트 탭을 마우스 오른쪽 단추로 클릭 한 다음 코드보기 상황에 맞는 메뉴 및 열린 애플리케이션 용 Microsoft Visual Basic 창에서 다음 코드를 복사하여 빈 모듈에 붙여 넣습니다.

VBA 코드 : 셀 값이 변경 될 때 매크로 실행 :

Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Address = "$A$1" Then
        Call Mymacro
    End If
End Sub

셀이 변경되면 문서 실행 매크로 1

주의 사항: 위 코드에서 A1 코드를 실행하려는 특정 셀입니다. 마이 매크로 실행하려는 매크로 이름입니다. 필요에 따라 변경하십시오.

2. 그런 다음 코드 창을 저장하고 닫으십시오. 이제 A1 셀에 값을 입력하거나 변경하면 특정 코드가 즉시 트리거됩니다.


화살표 블루 오른쪽 거품 VBA 코드를 사용하여 범위에서 셀 값이 변경 될 때 매크로 실행 또는 호출

셀 범위에서 셀 값이 변경 될 때 매크로를 실행하거나 트리거하려면 다음 코드가 도움이 될 수 있습니다.

1. 셀 값이 변경되면 매크로를 실행할 시트 탭을 마우스 오른쪽 단추로 클릭 한 다음 코드보기 상황에 맞는 메뉴 및 열린 애플리케이션 용 Microsoft Visual Basic 창에서 다음 코드를 복사하여 빈 모듈에 붙여 넣습니다.

VBA 코드 : 범위에서 셀 값이 변경 될 때 매크로 실행 :

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("A1:B100")) Is Nothing Then
Call Mymacro
End If
End Sub

셀이 변경되면 문서 실행 매크로 2

주의 사항: 위 코드에서 A1 : B100 코드를 실행하려는 특정 셀입니다. 마이 매크로 실행하려는 매크로 이름입니다. 필요에 따라 변경하십시오.

2. 그런 다음 코드 창을 저장하고 닫습니다. 이제 A1 : B100의 셀에 값을 입력하거나 변경하면 특정 코드가 한 번에 실행됩니다.


여러 통합 문서에서 모든 매크로 제거

Excel 용 Kutools's 모든 매크로 일괄 제거 유틸리티를 사용하면 필요에 따라 여러 통합 문서에서 모든 매크로를 제거 할 수 있습니다. 지금 Excel 용 Kutools를 다운로드하여 무료로 사용해보십시오!

Excel 용 Kutools: 300 개 이상의 편리한 Excel 추가 기능으로 30 일 동안 제한없이 무료로 사용해 볼 수 있습니다. 지금 다운로드 및 무료 평가판!


관련 기사 :

Excel에서 인쇄하기 전에 매크로를 자동으로 실행하는 방법은 무엇입니까?

Excel에서 셀 값을 기반으로 매크로를 실행하는 방법은 무엇입니까?

Excel의 드롭 다운 목록에서 선택한 값을 기반으로 매크로를 실행하는 방법은 무엇입니까?

Excel에서 하이퍼 링크를 클릭하여 매크로를 실행하는 방법은 무엇입니까?

통합 문서에서 시트를 선택할 때 매크로를 실행하는 방법은 무엇입니까?

최고의 사무 생산성 도구

🤖 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 (19)
Rated 5 out of 5 · 1 ratings
This comment was minimized by the moderator on the site
Good afternoon, could you help me, I have been trying to create a macro for some time, I create a macro that in cell c5, (makes a simple macro), when pressed it changes the color of a column x, if cell c5 is positioned in another cell like f8, how can I make the macro follow the cell to the new position, and be able to execute it, without the macro entering the code and changing the position internally. thanks greetings
Rated 5 out of 5
This comment was minimized by the moderator on the site
It worked, thanks for the help
This comment was minimized by the moderator on the site
This is exactly what I was looking go for. When a user enters a value in a cell, a simple sort macro would run. The macro runs fine on its own but I get an invalid use of property error using the suggested code.

What could be the issue?
This comment was minimized by the moderator on the site
I am using the code below to hide various columns depending on the selection from a drop-down box located in cell C3, but after a calculation is performed anywhere in the worksheet, ALL columns become UNHIDDEN. How do I fix this?

Private Sub Worksheet_Change(ByVal Target As Range)

Columns("D:F").AutoFit

Dim Proj1 As String
Dim Proj2 As String
Dim Proj3 As String
Dim Proj4 As String
Dim Proj5 As String
Dim Proj6 As String
Dim Proj7 As String
Dim Proj8 As String
Dim Proj9 As String
Dim Proj10 As String

Proj1 = ActiveWorkbook.Sheets("Projects").Range("A1").Value
Proj2 = ActiveWorkbook.Sheets("Projects").Range("A2").Value
Proj3 = ActiveWorkbook.Sheets("Projects").Range("A3").Value
Proj4 = ActiveWorkbook.Sheets("Projects").Range("A4").Value
Proj5 = ActiveWorkbook.Sheets("Projects").Range("A5").Value
Proj6 = ActiveWorkbook.Sheets("Projects").Range("A6").Value
Proj7 = ActiveWorkbook.Sheets("Projects").Range("A7").Value
Proj8 = ActiveWorkbook.Sheets("Projects").Range("A8").Value
Proj9 = ActiveWorkbook.Sheets("Projects").Range("A9").Value
Proj10 = ActiveWorkbook.Sheets("Projects").Range("A10").Value

Dim xRG As Range
Dim xHRow As Integer
Set xRG = Range("C3")
If Not Intersect(Target, xRG) Is Nothing Then

If Target.Value = Proj1 Then
Application.Columns("E:F").Hidden = True
Application.Columns("D").Hidden = False

ElseIf Target.Value = Proj2 Then
Range("D:D, F:F").EntireColumn.Hidden = True
Application.Columns("E").Hidden = False

End If
End If
End Sub
This comment was minimized by the moderator on the site
I am trying to automate 1 workbook (BOM) when another workbook(Parts Status) makes changes. The Parts status file updates every 15 minutes. I need to know how to automate a specific column when these changes occur? Any ideas
This comment was minimized by the moderator on the site
Hi guys, I am solving the following issue: I want to scrape a title of website when link inserted in column A and put this value to relevant cell (next to it) in column B. The issue seems to be that once I paste the website in column A, the code reruns the entire list from column A2 to "last row" as defined in the code. Is there any way to only modify column B once a single column A is modified? I.e. if Ipaste a link in column A36 I get a title in B36, regardless of whether the cell is in the middle of the used range or at the very bottom. I would like to use this without having to re-run multiple inputs as it currently stands; (i.e. the loop "for i =2 to last row")? Also, I would like to change the below from Modular macro i.e. sub to private sub reacting to change (i.e. intersect function) where the 'target' is any cell from A:A range. Many thanks!


Sub get_title_header()



Dim wb As Object

Dim doc As Object

Dim sURL As String

Dim lastrow As Long

lastrow = Sheet1.Cells(Rows.Count, "A").End(xlUp).row



For i = 2 To lastrow

Set wb = CreateObject("internetExplorer.Application")

sURL = Cells(i, 1)



wb.navigate sURL

wb.Visible = False



While wb.Busy

DoEvents

Wend



''HTML document

Set doc = wb.document



Cells(i, 2) = doc.Title



On Error GoTo err_clear

Cells(i, 3) = doc.GetElementsByTagName("h1")(0).innerText

err_clear:

If Err <> 0 Then

Err.Clear

Resume Next

End If

wb.Quit

Range(Cells(i, 1), Cells(i, 3)).Columns.AutoFit

Next i



End Sub




Thank YOU!
This comment was minimized by the moderator on the site
Hola buenas tardes
quisiera saber el codigo para que se active una macro cuando cambia el valor de una celda de una columna, pero este valor cambia por formula,sin que el usuario introduzca ningun valor.
This comment was minimized by the moderator on the site
The macro that you are calling where do you have this located? I have mine in the Modules folder but when I put any value in any cell of the worksheet I get a Compile error saying:
Expected variable or procedure, not module.

Please help.
This comment was minimized by the moderator on the site
Hi, DrCartwright,
Sorry for replying to you so late.
Yes, as you said, the macro code should be located into the Module, and you need to change the code name to your own name as following screenshot shown:
This comment was minimized by the moderator on the site
Hey, useful code. I was thinking if it was possible to insert a ring around the cells that are changed as they are changed? And reset the circles every Monday ?
This comment was minimized by the moderator on the site
Hello, Kevin,
Here is no idea for solving your problem, if you have any good solution, please comment here.
This comment was minimized by the moderator on the site
Worked great for me! My dilemma is that I want it to be a relative reference macro and there is a difference between hitting enter to save the entry and delete to clear the cell.
There are no comments posted here yet
Load More
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations