Auto refresh data

rakupareek

New Member
Joined
Dec 29, 2023
Messages
38
Office Version
  1. 2016
Platform
  1. Windows
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rng As Range
    Dim cell As Range
    Dim dataSheet As Worksheet
    Dim selectedValue As String

    Set rng = Me.Range("A4:A22")
    Set dataSheet = ThisWorkbook.Sheets("Data Input Sheet")
    If Not Intersect(Target, rng) Is Nothing Then
    Application.EnableEvents = False
      
For Each cell In Intersect(Target, rng)
            If cell.Value = "House Rent Allowance" Then
            Me.Range("P" & cell.Row).Value = dataSheet.Range("F14").Value
            ElseIf cell.Value = "Children Edu Allowance" Then
            Me.Range("P" & cell.Row).Value = dataSheet.Range("F18").Value
            ElseIf cell.Value = "Children Hostel Allowance" Then
            Me.Range("P" & cell.Row).Value = dataSheet.Range("F19").Value
            Else
            Me.Range("P" & cell.Row).ClearContents
            End If
        Next cell
        Application.EnableEvents = True
    End If
    Exit Sub
End Sub

Using this VBA but when I change some value in Data Input Sheet then data does not refresh.
Can possible to refresh data automatic when I change any value
 
It should if the values match the ones in your code, unless events have become disabled somehow. Try running this routine and see what the message says:

VBA Code:
sub checkevents()
if application.enableevents then 
msgbox "Events are enabled"
else
msgbox "Events are disabled"
end if
end sub
 
Upvote 0

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Wait, are you clearing the data from column A, then column P? You don't need to touch column P yourself - the code does that. If you do it after changing column A, then P will all remain blank until you change data in A again.
 
Upvote 0
Then that is the problem - the code isn't even running. Restart Excel then try the code again.
 
Upvote 0
If events are still disabled then you must have some other code that is disabling them.
 
Upvote 0
My sheet is password protected pasword is 1234
Is this stopping the code run
 
Upvote 0
You would get an error if that were the problem.
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

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