Adapt code to make dynamic

ddub25

Well-known Member
Joined
Jan 11, 2007
Messages
617
Office Version
  1. 2019
Platform
  1. Windows
Sub GState()
If Range("F81") + Range("F82") > 0 Then
Range("H93").Value = "IP"
Else
Range("H93").Value = "GE"
End If
End Sub

I want to make this code dynamic so that the moment when the result changes from "IP" to "GE" is recognised and "END" is outputted into "H94". The code would need to be re-checking for the change in state continuously every second or so.

Can anyone help with adapting this code?
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Sub GState()
If Range("F81") + Range("F82") > 0 Then
Range("H93").Value = "IP"
Else
Range("H93").Value = "GE"
End If
End Sub

I want to make this code dynamic so that the moment when the result changes from "IP" to "GE" is recognised and "END" is outputted into "H94". The code would need to be re-checking for the change in state continuously every second or so.

Can anyone help with adapting this code?
Are cells F81 and F82 manual entries or do they have formulas in them? What do you want in H94 if "GE" changes to "IP"?
 
Upvote 0
"Are cells F81 and F82 manual entries or do they have formulas in them?"
F81 and F82 will not be manual entries, an external source will be inputting values automatically (will not have formulas in them), although at the moment, while I am testing the code I am manually entering in these cells.

"What do you want in H94 if "GE" changes to "IP"?"
It can be left blank when this happens
 
Upvote 0
"Are cells F81 and F82 manual entries or do they have formulas in them?"
F81 and F82 will not be manual entries, an external source will be inputting values automatically (will not have formulas in them), although at the moment, while I am testing the code I am manually entering in these cells.

"What do you want in H94 if "GE" changes to "IP"?"
It can be left blank when this happens
This is sheet code - install it following the steps below. Once installed it will react automatically to manual changes in either cell F81 or F82. Don't know if it will work with your external source since you didn't indicate what that source is.

To install the code:
1. Right-click the worksheet tab you want to apply it to and choose 'View Code'. This will open the VBE window.
2. Copy the code below from your browser window and paste it into the white space in the VBE window.
3. Close the VBE window and Save the workbook. If you are using Excel 2007 or a later version do a SaveAs and save it as a macro-enabled workbook (.xlsm file extension).
4. Make sure you have enabled macros whenever you open the file or the code will not run.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("F81")) Is Nothing Or Not Intersect(Target, Range("F82")) Is Nothing Then
    Application.EnableEvents = False
    If Range("F81") + Range("F82") > 0 Then
        Range("H93").Value = "IP"
        Range("H94") = ""
    Else
        Range("H93").Value = "GE"
        Range("H94").Value = "END"
    End If
    Application.EnableEvents = True
End If
End Sub
 
Upvote 0
Thanks very much, Joe, that's a great help. Works great and thanks for the thorough explanation, Dan
 
Upvote 0

Forum statistics

Threads
1,214,947
Messages
6,122,413
Members
449,082
Latest member
tish101

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