Worksheet_Change Variable to Module

tdh2023

New Member
Joined
Feb 1, 2023
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Hello everybody :),

I am fairly new to Excel VBA and i struggle to figure out how to pass a variable from the worksheet_change to a module where the variable is picked up and is printed.
I hope you guys can help me.

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   
    If Range("C3").Value = "YES" Then
        Ergebnis = "XXX"
    ElseIf Range("C3").Value = "NO" Then
        Range("C4").Locked = False
   
        If Range("C4").Value = "NO" Then
            Ergebnis = "ZZZ"
        ElseIf Range("C4").Value = "YES" Then
            Range("C5").Locked = False
            Range("C6").Locked = False
            Range("C7").Locked = False
           
            If Range("C5").Value = "YES" Or Range("C6").Value = "YES" Or Range("C7").Value = "YES" Then
                Range("C8").Locked = False
                Range("C9").Locked = False
                Range("C10").Locked = False
                Range("C11").Locked = False
                Range("C12").Locked = False
                Range("C13").Locked = False
                Range("C14").Locked = False
                Range("C15").Locked = False
            End If
        End If
    End If

End Sub

Sub Button_Ident_Click()
    Sheets("Identification").Select
    Range("c3").Select
    Ergebnis = Empty
   
    Range("c3").Select
    Beginn = MsgBox("This Object is /n: " & Ergebnis, vbOKOnly, "The Result is")
    Range("e1").Value = Ergebnis
    Sheets("PRINT").Select
    Range("e31").Value = Ergebnis
End Sub
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Declare a Public variable, update it via the event macro, and use it in the module macro.
 
Upvote 1
Thank you very much. I got it to work now. My problem was that I did declare it a public Variable in both.
 
Upvote 0
Thanks for the positive feedback(y), glad having been of some help.
 
Upvote 0

Forum statistics

Threads
1,214,920
Messages
6,122,279
Members
449,075
Latest member
staticfluids

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top