Skip to main content

 Conas macra a rith go huathoibríoch nuair a athraíonn toradh foirmle cille?

Ag ceapadh, tá liosta foirmlí agam atá bunaithe ar na sonraí i gcolún A agus i gcolún B mar a leanas an pictiúr a thaispeántar, anois, ba mhaith liom macra-chód sonrach a reáchtáil go huathoibríoch nuair a athraíonn toradh na foirmle agus a chealla coibhneasta ag athrú. An bhfuil aon smaoineamh maith ann an post seo a réiteach in Excel?

Macra a reáchtáiltear go huathoibríoch nuair a athraíonn toradh foirmle cille le cód VBA


Macra a reáchtáiltear go huathoibríoch nuair a athraíonn toradh foirmle cille le cód VBA

Is féidir leis an gcód VBA seo a leanas cabhrú leat cód sonrach a fhorghníomhú go huathoibríoch nuair a athraíonn cill toradh na foirmle, déan mar seo é le do thoil:

1. Cliceáil ar dheis ar an táb bileog a theastaíonn uait a úsáid, agus ansin roghnaigh Féach an cód ón roghchlár comhthéacs, san oscailt Microsoft Visual Basic d’iarratais an cód seo a leanas a fhuinneogú, a chóipeáil agus a ghreamú isteach sa Mhodúl bán:

Cód VBA: Macra a reáchtáiltear go huathoibríoch nuair a athraíonn toradh foirmle cille:

Private Sub Worksheet_Calculate()
'Updateby Extendoffice
    Dim Xrg As Range
    Set Xrg = Range("C2:C8")
    If Not Intersect(Xrg, Range("C2:C8")) Is Nothing Then
    Macro1
    End If
End Sub

nótaí: Sa chód thuas, C2: C8 an raon cealla foirmle is mian leat a úsáid ,macó1 is ainm don mhacra atá tú ag iarraidh a rith go huathoibríoch. Athraigh é le do riachtanas.

2. Ansin sábháil agus dún an fhuinneog cód seo, anois, nuair a athraíonn na sonraí i raon A2: B8 chun go n-athróidh toradh na foirmle, spreagtar do chód macra sonrach ag an am céanna.

Uirlisí Táirgiúlachta Oifige is Fearr

🤖 Kutools AI Aide: anailís sonraí a réabhlóidiú bunaithe ar: Forghníomhú Chliste   |  Gin Cód  |  Cruthaigh Foirmlí Saincheaptha  |  Anailís a dhéanamh ar Sonraí agus Cairteacha a Ghin  |  Feidhmeanna Kutools a agairt...
Gnéithe Coitianta: Faigh, Aibhsigh nó Aithnigh Dúblaigh   |  Scrios Sraitheanna Bána   |  Comhcheangail Colúin nó Cealla gan Sonraí a Chailleadh   |   Babhta gan Foirmle ...
Cuardaigh Super: Ilchritéir VLookup    VLookup Illuachanna  |   VLookup Trasna Ilbhileoga   |   Amharc doiléir ....
Liosta anuas Casta: Go tapa Cruthaigh Liosta Anuas   |  Liosta anuas Cleithiúnach   |  Liosta Buail Isteach Ilroghnacha ....
Bainisteoir Colún: Cuir Líon Sonrach Colún leis  |  Colúin Bog  |  Scoránaigh Stádas Infheictheachta na gColún Ceilte  |  Déan comparáid idir Raonta & Colúin ...
Gnéithe Réadmhaoin: Fócas Eangaí   |  Amharc Dearaidh   |   Barra Mór na Foirmle    Leabhar Oibre & Bainisteoir Bileog   |  Leabharlann Acmhainní (Uaththéacs)   |  Piocálaí Dáta   |  Comhcheangail Bileoga Oibre   |  Criptigh/Díchriptigh Cealla    Seol Ríomhphost trí Liosta   |  Scagaire Super   |   Scagaire Speisialta (scagaire trom/iodálach/stailc tríd...) ...
Barr 15 Uirlisí12 Téacs uirlisí (Cuir Téacs, Bain Carachtair,...)   |   50 + Cairt cineálacha (Cairt Gantt,...)   |   40+ Praiticiúil Foirmlí (Ríomh aois bunaithe ar lá breithe,...)   |   19 Insertion uirlisí (Cuir isteach Cód QR, Ionsáigh Pictiúr ón gCosán,...)   |   12 Tiontú uirlisí (Uimhreacha le Focail, Comhshó Airgeadra,...)   |   7 Cumaisc & Scoilt uirlisí (Sraitheanna Comhcheangail Casta, Cealla Scoilt,...)   |   ... agus eile

Supercharge Do Scileanna Excel le Kutools le haghaidh Excel, agus Éifeachtúlacht Taithí Cosúil Ná Roimhe. Kutools le haghaidh Excel Tairiscintí Níos mó ná 300 Ardghnéithe chun Táirgiúlacht a Treisiú agus Sábháil Am.  Cliceáil anseo chun an ghné is mó a theastaíonn uait a fháil ...

Tuairisc


Tugann Tab Oifige comhéadan Tabbed chuig Office, agus Déan Do Obair i bhfad Níos Éasca

  • Cumasaigh eagarthóireacht agus léamh tabbed i Word, Excel, PowerPoint, Foilsitheoir, Rochtain, Visio agus Tionscadal.
  • Oscail agus cruthaigh cáipéisí iolracha i gcluaisíní nua den fhuinneog chéanna, seachas i bhfuinneoga nua.
  • Méadaíonn do tháirgiúlacht 50%, agus laghdaíonn sé na céadta cad a tharlaíonn nuair luch duit gach lá!
Comments (10)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Hello team,

I know this is a old topic but how to have a mix between this calculate method and this: https://www.extendoffice.com/documents/excel/1895-excel-record-date-and-time-when-cell-changes.html?

The goal is to record a date on the next cell every time that the calculated values change for every cell in a column.

Regards,
Tiago
This comment was minimized by the moderator on the site
Hey guys,
Below is the code and I want to lock cells A2 and A3 after cell A1 (A1 = B1+C1) is changing in results change either B1 or C1 or both. But it does not work. Could anyone help with that, please?

Private Sub Worksheet_Calculate()

Dim sPass
sPass = "123"
Dim rng As Range
Set rng = [A2:A3]
If Not Intersect(rng, [A1]) Is Nothing Then
With ActiveSheet
.Unprotect Password:=sPass
.Cells.Locked = False
Static oldValue
If Range("A1") <> oldValue Then
rng.Locked = True
.Protect Password:=sPass
oldValue = Range("A1").Value

End If
End With

End If
End Sub
This comment was minimized by the moderator on the site
"Set Xrg = Range("C2:C8")
If Not Intersect(Xrg, Range("C2:C8")) Is Nothing Then"
this condition is ALWAYS encountered....
Make sense ???
Or is there something I didn't understand ?
This comment was minimized by the moderator on the site
That right, did you solve this problem, and could you share for me, please?
This comment was minimized by the moderator on the site
Hey guys,
I used the following code for this problem, hope it helps someone:

Private Sub Worksheet_Calculate()
Static oldValue
If Range("MyNamedRange") <> oldValue Then
CodeHere
oldValue = Range("MyNamedRange").Value
End If
End Sub
This comment was minimized by the moderator on the site
sorry it dosn't work it works if i put data manually. but i want to work it automatically bcz my data is updating by rand calcaulate
This comment was minimized by the moderator on the site
So, what is my macro name. where can i find my macro name?
This comment was minimized by the moderator on the site
Hello, Cenk,
The macro name is the macro code you have inserted into the Excel file, and you just need to change the Macro1 in the above code to your own.
For example, i insert a code here, and the macro name is: ColorCompanyDuplicates

Sub ColorCompanyDuplicates()
'Updateby Extendoffice 20160704
Dim xRg As Range
Dim xTxt As String
Dim xCell As Range
Dim xChar As String
Dim xCellPre As Range
Dim xCIndex As Long
Dim xCol As Collection
Dim I As Long
On Error Resume Next
If ActiveWindow.RangeSelection.Count > 1 Then
xTxt = ActiveWindow.RangeSelection.AddressLocal
Else
xTxt = ActiveSheet.UsedRange.AddressLocal
End If
Set xRg = Application.InputBox("please select the data range:", "Kutools for Excel", xTxt, , , , , 8)
If xRg Is Nothing Then Exit Sub
xCIndex = 2
Set xCol = New Collection
For Each xCell In xRg
On Error Resume Next
xCol.Add xCell, xCell.Text
If Err.Number = 457 Then
xCIndex = xCIndex + 1
Set xCellPre = xCol(xCell.Text)
If xCellPre.Interior.ColorIndex = xlNone Then xCellPre.Interior.ColorIndex = xCIndex
xCell.Interior.ColorIndex = xCellPre.Interior.ColorIndex
ElseIf Err.Number = 9 Then
MsgBox "Too many duplicate companies!", vbCritical, "Kutools for Excel"
Exit Sub
End If
On Error GoTo 0
Next
End Sub
This comment was minimized by the moderator on the site
What's the point of the condition? It'll always return true...in other words: it'll run without it. This also runs whenever any cells on the sheet change value.
This comment was minimized by the moderator on the site
Thanks a lot! This really helped me out.
Is there any method to retrieve the address of the changed cell (with formula i.e Column C in this example).
Thanks.
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations