If for example cell A1 begins empty with no data in it other than a formula and something occurs to change the state of cell A1 to a value which triggers a change in cell B1 (a variable), can I use this to fire a sheet change macro ????
Wish to trigger a macro on sheet change based on every cell in column C, is this even possible ???
Or, is a change in a variable (C1) for example, the same as that of a DIRECT user keyboard input for example ???
Private Sub Worksheet_Change(ByVal Target As Range) Dim c As Range
If Not Application.Intersect(Target, Columns(3)) Is Nothing Then
Application.EnableEvents = False
For Each c In Target
I have an application that updates the text string in A1 every x minutes (time may vary). I'm trying to develop a toutine that will trigger a Macro/call a function/subroutine once only on each change of data (and then not trigger again until the next change...and must only trigger on change of data in this specific cell). So the timeline looks like this
start A1 = "Apples", Fire macro once
start + 10mins A1 = "Oranges", Fire Macro Once again
start + 25mins A1 = "Pears", Fire Macro Once again
Triggering the macro is no problem but constraining to one triggering is proving a problem (for me anyway) and is really holding up my application progress.
Is there a way to write a Worksheet_SelectionChange (ByVal Target As Range) event in module after creating a sheet in VBA? I constantly delete a sheet, then repopulate it with a new one that is empty, but I need to add some code that happens if they should change a particular cell. It worked when I ran it on a worksheet without refreshing, but as soon as I cleared and repopulated the sheet, it was gone. Is there a way to preserve this?
I have a chart with 2 Y axis. I am attempting to write some code that will update both axis with the same max & min value that is triggered by the combobox selection. The code will update the axis but is not triggered by the combobox selection.
I have a user entering text into a textbox on my userform. The textbox is linked to a textbox change event. Unfortunately, the event is triggered as soon as the user enters the first character of their entry. I'm thinking that the textbox change event isn't the most appropriate for this scenario. What would I need to do to trigger the code (of the change event) with hitting ENTER when finished?
If no program (code) is running and Calculation is turned to ON, what expression could be placed into a cell that will change on its own that could necessarily and periodically trigger a change event subroutine. How can I trigger a change event when nothing is changing?
I have a situation where my code simply stops running so i need a change event to assess whether code is running (or not) and to issue a warning to the programmer that the code is, in fact, stalled. The change event subroutine has not only a warning system but a "timetorun" feature that will come back and warn again until the programmer can address the issue.
Unfortunately, I have to deal with this issue in a check and balance fashion because my many attempts to seek solutions to a stalled program (root cause) have failed.
I have a set of data in a given range with one column indicating "priority" of 0, 1, 2, or 3 for each row. I would like to be able to allow users of the file to filter the data simply by changing the text of a given cell, or by choosing among filter options from a drop down. For example, I would label the control cell "show items up to priority:" and then let them enter 1, 2, or 3.
The "auto filter" option won't work because if they use the "sort" options in the drop down it will mess everything up. I would only want to use the auto-filter drop down if I could suppress the sorting options and the other filter options. (I'm after custom options of <4, <3, <2, <1).
Also, the advanced filter method doesn't seem to work well because users would apparently have to re-run the filter each time they want to change the criteria range value.
I've heard of macros that can be triggered based on changes to data in a given cell, but how is this done in this situation?
I guess programming a custom drop down box for selecting 0, 1, 2 or 3 would work just as well as having them type the number in. But I'm not sure how this could be done either.
I am sure that a worksheet change would be the best way to go for this, but I am unsure how to test for this.
I am looking to prevent users from using a select set of colors for highlighting. If the user tries to highlight using one of these invalid colors, I would like to flag a message telling the user that this color is reserved and highlight the selection to the previous color.
The previous color may be a tricky part as I do not know if this can be done.
So, I have a worksheet with a bunch of combo boxes. The code for the worksheet is below. The issue I'm having is that anytime I drag and drop a cell anywhere on the page, every single control on the worksheet triggers. VB runs through all the code on the sheet, TWICE(I used the debugger extensively trying to find a solution), and causes dozens of successive re-calculations of the entire workbook, which has a couple of tables. This happens on any cell drag-drop on the worksheet, or when I click the command button on the screen.
I have no clue what is causing this. Even more bizarre, it seems to trigger a custom function which is located in a separate module, and isn't even utilized on the worksheet in question. I guess this is because it makes the whole workbook re-calculate?
I have the code below that is two separate activities and I want to change the second activity from a cell trigger (Set KeyCells = Range("K42:AD42")) to a button trigger. I need to first to remain unchanged.
I'd be ok if this was just one macro that I could assign to a button but because its two and I need to write the second's to clicking a button I'm over my head.
Its occured to me while writing this that because it'll be a range of buttons I'll probably need to make each one an individual code? Is this the case? If so I may have to just keep this as it is.
I have a bit of code that calls a formatting sub depending on which cell is modified. It is triggered by the Worksheet_Change event, determines which cell is modified, and either calls the formatting sub or doesn't based on the location of the modified cell.
Some of the columns in the sheet have data validation with drop downs. If I select a value from the drop down, it doesn't trigger the Worksheet_Change. If I type a value into the same cell, it does.
This was apparently an issue in Excel '97, but supposedly fixed in '03?
I have cut and paste some code provided by members of this great forum to insert a row in a second worksheet at the same row number when one is inserted in the active worksheet. e.g. If I insert a new line at Row 14 in worksheet "admin" I also get a new row at Row 14 in worksheet "report".
Code is as follows:
Private Sub Worksheet_Change(ByVal Target As Range) Set sourcebook = ThisWorkbook Set sourcesheet = sourcebook.Worksheets("admin") Set targetbook = ThisWorkbook Set targetsheet = targetbook.Worksheets("report") myRow = ActiveCell.Row targetsheet.Activate ActiveSheet.Rows(myRow).EntireRow.Insert sourcesheet.Activate End Sub
However, anything I do in worksheet "admin" triggers a new row to be inserted in "report".... If I change text in any cell, or make any changes at all, I get a new row in "report".
Is there a way to restrict this action to only a line insert?
When ever I update my external CSV file and hit refresh all data, I get #REF! Errors. The CSV file has a table that changes daily. Thus the "A" Column has a different number of rows depending on the day. The problem is that Monday the CSV file will contain 700 Rows, while on Friday it will have 200 Rows. I end up with a lot of #REF! Errors friday. How do I write the code so that (A561 for example) does not change regardless if it can reference the target cell or not? I even thought of making a macro that just copied the formula into all of the cells after each refresh, but there must be a better way.
Example code =IF(A561>0,IF(Start!$H$2="Monday",'calculations-mon-sat'!O561,calculation!O561),"")
I'm trying to run a macro anytime cells G2, J2, M2, O2, P2, S2, V2, Y2, AB2, AE2, AH2, AK2, AN2, AQ2 change.
Right now I have the below code which is working well, but I only have it set for G2. Do you know what the notation is to make the target range multiple cells?
Also, I use the xlDown command in my sorting code, but later on it reverts back to "A5:AT60"... is there any way I can remove these specific cell references? I want to avoid having to re-write the macro every time my selection shrinks or expands.
Code: Private Sub Worksheet_Change(ByVal Target As Range) If Not Intersect(Target, Range("G2")) Is Nothing Then Rows("5:5").Select
I need to hide/unhide a couple of rows based on the result of a formula in the Target Range. Basically, Cell D2 contains the results of a sum (a+ B), if this is greater than 10,000, unhide the next row.
Below is an example from the ozgrid forum illustrating the worksheet change event. Not sure of the meaning of 'Do nothing if more than one cell is changed" on the 2nd row of the code. Does it means that if a value is entered in other cells, the code will not fire?
Private Sub Worksheet_Change(ByVal Target As Range) 'Do nothing if more than one cell is changed or content deleted If Target.Cells.Count > 1 Or IsEmpty(Target) Then Exit Sub If Target.Address = "$A$1" Then 'Ensure target is a number before multiplying by 2 If IsNumeric(Target) Then 'Stop any possible runtime errors and halting code On Error Resume Next 'Turn off ALL events so the Target * 2 does not _ put the code into a loop. Application.EnableEvents = False Target = Target * 2 'Turn events back on Application.EnableEvents = True 'Allow run time errors again On Error Goto 0 End If End If End Sub
I'm trying to create a sheet where clicking in a range brings up, in my users words, "a box I can type loads of comments in". They want some kind of flag in this cell showing if comments are posted or not. So far so ok, got the userform to pop up using the selection change event below and dump the actual comments somewhere the user won't look. A rather inelegant IF statement to see if there's anything in the dump cell gives them their flag.
Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range) If Intersect(Target, Range("B2:B300")) Is Nothing Then Exit Sub UserForm1.TextBox1.Value = ActiveCell.Offset(0, 10).Value UserForm1.show End Sub
So what's the problem? When I select entire rows, the userform pops up. Is this unavoidable?
how to allow both these codes to work on say sheet 1. I can get one to work just fine. So, any tips on how to get them both to work on the same sheet would be great.
Private Sub Worksheet_Activate()
Private Sub Worksheet_Change(ByVal Target As Excel. Range) With Worksheets("Sheet1") If Not Application.Intersect(Target, .Range("n1:n200")) Is Nothing Then If Target = "S" Or Target = "s" Then Target = "Submitted" If Target = "A" Or Target = "a" Then Target = "Approved" If Target = "I" Or Target = "i" Then Target = "Investgating" Else End If End With End Sub
I want to trigger a macro that refreshes a pivot table but I only want to trigger the macro after 15 seconds. The reason is that I am pulling the source data from access mdb so I want only to refresh the data once the data is pulled.
A1 is a drop-down list, created from Data> Validation>List, which lists 3 different words (Text1, Text2, Text3). I have recorded 3 macros (Macro1, Macro2, Macro3). Here's what I want to happen:
When Text1 is selected in A1, I want Macro1 to run (same for Text2/Macro2 and Text3/Macro3). I want the user to be able to change this value as many times as they wish and have the corresponding Macro run each time. I've tried creating the appropriate code in Editor using other threads on this forum, but I can't seem to figure it out.
I used to use Excel many many years ago for all my basic business databases and pivot table reports (so was at a basic competency level) and want to use it again but it has been quite a while and I can't remember how to do the following.....
I want to build a database of sales and purchase info in say 'sheet 1' - let's say 30 different headed columns and then many lines of different information under each column.
In 'sheet 2' I want to create an invoice template of my own design (I can do easily) for printing.
This template will need to extract say 10 bits of information from a particular row and then put them in a certain place on this sheet.
How can I type in one piece of information in a cell on sheet 2 (say the invoice or line number of the database) and that will then trigger all the other needed information from that particular line in sheet one onto this template?
I know it can be done but for life of me can not remember the formulas to use for these other cells in sheet 2 based on the info put in that one 'trigger' cell
I have a series of macros altering various workbooks and sheets. They're numbered Step1, Step2, etc. In my Step5 I have a series of Case statements in a macro, and I don't know how to get it to do what I want next. I have NOT tried running this code yet, and I'm sure I have something(s) wrong in it.
1) If the selection in DstWbk, sheet "Steps", is "01DSP" through "11DSP" the macro needs to delete specific columns in the SrcWbk, and then move to the next step (6).
2) If the selection in DstWbk, sheet "Steps", is "*DSP" the macro needs to go directly to the next step (6)
3) If the selection in DstWbk, sheet "Steps", is anything else the macro needs to flash a generic "No Data found" message and move on to Step7.
The part of the code that's throwing me begins at 'Select only the specific regional data' and ends at the "Case Else MsgBox"
I'm creating a small Excel RPG where the player moves the around a blank worksheet with the walls of a maze appearing as you approach them (think dark corridors, you can see only 1 cell in all directions around you).
The players current location is shown by excel setting the activecell to the players location. Currently I have four buttons labeled Up, Down, Left and Right which the player clicks to move in the desired direction.
The testers were frequently missing the four movement buttons and this would put the activecell outside of the maze next to one of the buttons. They'd have to move it back manually.
I would like for the players to move around using the arrow keys to use the activecell, as you would normally move around a sheet... but before each movement there is a procedure that check IF the player can move in the desired direction or not (cell borders used for walls), and then once they've moved there are more procedures to check for monsters treasure chests etc.
How can I make the arrow keys trigger the macros that the Up, Down, Left and Right buttons currently trigger, and not just move the activecell?