Direkt zum Inhalt

Wie führe ich ein Makro aus, wenn sich der Zellenwert in Excel ändert?

Normalerweise können wir in Excel die Taste F5 oder die Schaltfläche Ausführen drücken, um den VBA-Code auszuführen. Haben Sie jemals versucht, den spezifischen Makrocode auszuführen, wenn sich ein Zellenwert ändert? In diesem Artikel werde ich einige schnelle Tricks vorstellen, um diesen Job in Excel zu bearbeiten.

Führen Sie ein Makro aus oder rufen Sie es auf, wenn sich ein bestimmter Zellenwert mit dem VBA-Code ändert

Führen Sie ein Makro aus oder rufen Sie es auf, wenn sich ein Zellenwert in einem Bereich mit VBA-Code ändert


Pfeil blau rechte Blase Führen Sie ein Makro aus oder rufen Sie es auf, wenn sich ein bestimmter Zellenwert mit dem VBA-Code ändert

Um einen Makrocode durch Ändern eines Zellenwerts auszuführen, kann Ihnen der folgende VBA-Code einen Gefallen tun: Gehen Sie wie folgt vor:

1. Klicken Sie mit der rechten Maustaste auf die Registerkarte Blatt, auf der Sie das Makro ausführen möchten, wenn sich der Zellenwert ändert, und wählen Sie dann Code anzeigen aus dem Kontextmenü und im geöffneten Microsoft Visual Basic für Anwendungen Kopieren Sie im Fenster den folgenden Code und fügen Sie ihn in das leere Modul ein:

VBA-Code: Makro ausführen, wenn sich der Zellenwert ändert:

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

doc Makro ausführen, wenn sich die Zelle ändert 1

Note: Im obigen Code, A1 ist die spezifische Zelle, auf der Sie den Code ausführen möchten. Mein Makro ist der Makroname, den Sie ausführen möchten. Bitte ändern Sie sie nach Ihren Wünschen.

2. Speichern und schließen Sie dann das Codefenster. Wenn Sie jetzt den Wert in Zelle A1 eingeben oder ändern, wird der spezifische Code sofort ausgelöst.


Pfeil blau rechte Blase Führen Sie ein Makro aus oder rufen Sie es auf, wenn sich ein Zellenwert in einem Bereich mit VBA-Code ändert

Wenn Sie ein Makro ausführen oder auslösen möchten, wenn sich der Wert einer Zelle in einem Zellbereich ändert, kann der folgende Code hilfreich sein.

1. Klicken Sie mit der rechten Maustaste auf die Registerkarte Blatt, auf der Sie das Makro ausführen möchten, wenn sich der Zellenwert ändert, und wählen Sie dann Code anzeigen aus dem Kontextmenü und im geöffneten Microsoft Visual Basic für Anwendungen Kopieren Sie im Fenster den folgenden Code und fügen Sie ihn in das leere Modul ein:

VBA-Code: Führen Sie ein Makro aus, wenn sich ein Zellenwert in einem Bereich ändert:

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

doc Makro ausführen, wenn sich die Zelle ändert 2

Note: Im obigen Code, A1: B100 ist die spezifische Zelle, auf der der Code ausgeführt werden soll. Mein Makro ist der Makroname, den Sie ausführen möchten. Bitte ändern Sie sie nach Ihren Wünschen.

2. Speichern und schließen Sie dann das Codefenster. Wenn Sie jetzt einen Wert in eine beliebige Zelle von A1: B100 eingeben oder ändern, wird der spezifische Code sofort ausgeführt.


Entfernen Sie alle Makros aus mehreren Arbeitsmappen

Kutools for Excel's Batch Entfernen Sie alle Makros Das Dienstprogramm kann Ihnen dabei helfen, alle Makros nach Bedarf aus mehreren Arbeitsmappen zu entfernen. Laden Sie jetzt Kutools für Excel herunter und testen Sie es kostenlos!

Kutools for Excel: Mit mehr als 300 praktischen Excel-Add-Ins können Sie es innerhalb von 30 Tagen ohne Einschränkung testen. Jetzt herunterladen und kostenlos testen!


In Verbindung stehende Artikel:

Wie führe ich ein Makro automatisch aus, bevor ich in Excel drucke?

Wie führe ich ein Makro basierend auf dem Zellenwert in Excel aus?

Wie führe ich ein Makro basierend auf dem Wert aus, der aus der Dropdown-Liste in Excel ausgewählt wurde?

Wie führe ich ein Makro aus, indem ich in Excel auf Hyperlinks klicke?

Wie führe ich ein Makro aus, wenn ein Blatt aus einer Arbeitsmappe ausgewählt wird?

Beste Office-Produktivitätstools

🤖 Kutools KI-Assistent: Revolutionieren Sie die Datenanalyse basierend auf: Intelligente Ausführung   |  Code generieren  |  Erstellen Sie benutzerdefinierte Formeln  |  Analysieren Sie Daten und erstellen Sie Diagramme  |  Rufen Sie Kutools-Funktionen auf...
Beliebte Funktionen: Suchen, markieren oder identifizieren Sie Duplikate   |  Leere Zeilen löschen   |  Kombinieren Sie Spalten oder Zellen, ohne Daten zu verlieren   |   Runde ohne Formel ...
Super-Lookup: VLookup mit mehreren Kriterien    VLookup mit mehreren Werten  |   VLookup über mehrere Blätter hinweg   |   Unscharfe Suche ....
Erweiterte Dropdown-Liste: Erstellen Sie schnell eine Dropdown-Liste   |  Abhängige Dropdown-Liste   |  Mehrfachauswahl Dropdown-Liste ....
Spaltenmanager: Fügen Sie eine bestimmte Anzahl von Spalten hinzu  |  Spalten verschieben  |  Schalten Sie den Sichtbarkeitsstatus ausgeblendeter Spalten um  |  Vergleichen Sie Bereiche und Spalten ...
Ausgewählte Funktionen: Rasterfokus   |  Designansicht   |   Große Formelleiste    Arbeitsmappen- und Blattmanager   |  Ressourcen (Autotext)   |  Datumsauswahl   |  Arbeitsblätter kombinieren   |  Zellen verschlüsseln/entschlüsseln    Senden Sie E-Mails nach Liste   |  Superfilter   |   Spezialfilter (Filter fett/kursiv/durchgestrichen...) ...
Top 15 Toolsets12 Text Tools (Text hinzufügen, Zeichen entfernen, ...)   |   50+ Chart Typen (Gantt-Diagramm, ...)   |   40+ Praktisch Formeln (Berechnen Sie das Alter basierend auf dem Geburtstag, ...)   |   19 Einfügen Tools (QR-Code einfügen, Bild aus Pfad einfügen, ...)   |   12 Umwandlung (Conversion) Tools (Zahlen zu Wörtern, Currency Conversion, ...)   |   7 Zusammenführen & Teilen Tools (Erweiterte Zeilen kombinieren, Zellen teilen, ...)   |   ... und mehr

Verbessern Sie Ihre Excel-Kenntnisse mit Kutools für Excel und erleben Sie Effizienz wie nie zuvor. Kutools für Excel bietet über 300 erweiterte Funktionen, um die Produktivität zu steigern und Zeit zu sparen.  Klicken Sie hier, um die Funktion zu erhalten, die Sie am meisten benötigen ...

Beschreibung


Office Tab Bringt die Oberfläche mit Registerkarten in Office und erleichtert Ihnen die Arbeit erheblich

  • Aktivieren Sie das Bearbeiten und Lesen von Registerkarten in Word, Excel und PowerPoint, Publisher, Access, Visio und Project.
  • Öffnen und erstellen Sie mehrere Dokumente in neuen Registerkarten desselben Fensters und nicht in neuen Fenstern.
  • Steigert Ihre Produktivität um 50 % und reduziert jeden Tag Hunderte von Mausklicks für Sie!
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