Greetings,
is it possible to start a makro when opening a document and let in run in the background all the time?
Greetings,
is it possible to start a makro when opening a document and let in run in the background all the time?
Last edited by Eich; 08-05-2013 at 02:43 AM.
Hello Eich,
Most Macros run in the background all the time.
If you could upload a sample WorkBook of your requirements, we may be able to assist you.
Please consider:
Be polite. Thank those who have helped you. Then Click on the star icon in the lower left part of the contributor's post and add Reputation. Cleaning up when you're done. If you are satisfied with the help you have received, then Please do Mark your thread [SOLVED] .
The event handlers run all the time if you have established them.
You'd use a worksheet change event to cope with the original problem. If A1 is changed, check A2 and A3. If both are empty, exit. If one has a value, put the total in the other one. Repeat code for A2 and A3..
My initial thoughts anyway ... But now you've changed the title and the content, maybe that's not what you want.
Regards, TMS
Trevor Shuttleworth - Retired Excel/VBA Consultant
I dream of a better world where chickens can cross the road without having their motives questioned
'Being unapologetic means never having to say you're sorry' John Cooper Clarke
Sorry for the change of title and content, I thought I figured out the solution, but as it turns out, I did not. Exactly because I do not know how to check for a change of a cell. Basically I want to do this, but less dumb and in realtime:
TestNeu.xlsm
Thanks
Maybe the attached Workbook is what you want.
Also see the "Please consider" note at the bottom of this post.
Well, not exactly. For one, it doesn't work properly. It continues to sum up everything and produces an error on startup. I would prefer to alter my code in a way it works in realtime. Because it is easy to understand and stops when it has to. I'm sure the solution has something to do with this:
But I just don't know enough about the syntax to get it working in a timely fashion.If Not Application.Intersect(KeyCells, Range(Target.Address)) _ Is Nothing Then
I forgot to mention that although your Sub Sum Macro might need attention, as it would appear to me, I did not change it, since you may have a reason for having set it up that way.
Do you experience the same problem with the WorkBook I have provided you with?
Sorry, I've been busy ... but can I just say that choosing "Sum" as the name of a VBA routine is a really bad choice. "Sum" is an Excel/VBA reserved word for an Excel function so you might experience some conflict.
Whatever, it's bad practice and I would suggest that you change it.
You could perhaps use the following worksheet change event:
Private Sub Worksheet_Change(ByVal Target As Range) Dim rInputCells As Range Dim vInputCells Set rInputCells = Range("B2,D2,F2") vInputCells = Split(rInputCells.Address, ",") ' too many cells; possibly deleting everything If Target.Cells.Count > 1 Then Exit Sub ' clearing one of the cells of interest If Target.Value = "" Then Exit Sub ' not one of the cells of interest If Intersect(Target, rInputCells) Is Nothing Then Exit Sub ' check which cell has been changed Select Case Target.Address ' change index 0 Case vInputCells(0) If Range(vInputCells(1)) = "" And Range(vInputCells(2)) = "" Then Exit Sub Application.EnableEvents = False If Range(vInputCells(1)) = "" Then Range(vInputCells(1)) = Range(vInputCells(0)) + Range(vInputCells(2)) Else Range(vInputCells(2)) = Range(vInputCells(0)) + Range(vInputCells(1)) End If Application.EnableEvents = True ' change index 1 Case vInputCells(1) If Range(vInputCells(0)) = "" And Range(vInputCells(2)) = "" Then Exit Sub Application.EnableEvents = False If Range(vInputCells(0)) = "" Then Range(vInputCells(0)) = Range(vInputCells(1)) + Range(vInputCells(2)) Else Range(vInputCells(2)) = Range(vInputCells(1)) + Range(vInputCells(0)) End If Application.EnableEvents = True ' change index 2 Case vInputCells(2) If Range(vInputCells(0)) = "" And Range(vInputCells(1)) = "" Then Exit Sub Application.EnableEvents = False If Range(vInputCells(0)) = "" Then Range(vInputCells(0)) = Range(vInputCells(2)) + Range(vInputCells(1)) Else Range(vInputCells(1)) = Range(vInputCells(2)) + Range(vInputCells(0)) End If Application.EnableEvents = True Case Else End Select End Sub
Regards, TMS
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks