I use excel 2002 but some of my office are on 97, i want to add a small workbook open event code which works for me but debugs for the others?? The code is basically, go to a tab, on that tab and that range sort..
I have a reference sheet that the only cell that should be accessed is in col A
Rather than protecting the sheet I have made it so that what ever cell is selected it changes to select the cell in A
however if the selection is made using the col, header (ie clicking the C) it falls over.
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Intersect(ActiveCell, Range("A6:A1000")) Is Nothing Then 'makes sure A isn't already selected x = ActiveCell.End(xlToLeft).Cells.Count ActiveCell.Offset(0, -x).Select Else If Selection.Cells.Count > 1 Then ' fixes the problem of selecting a range that starts with an A ActiveCell.Select End If End If
However it will not update until I physically click on any cell within the U33 to U38 range.
How do I tell Excel that I physically clicked on any of these cells? I have tried Activate..., blank and re-populate, select cell, select range... In VBA it does not think it is being clicked on.. it is just doing the code... when done I have to again manually/physically click on it.
I need to to use VBA to copy a worksheet (which i've managed to do!), but I need the new worksheet to have a Worksheet_Change event. Now when I copy the worksheet, the event doesn't copy over (obviously as its a cut and paste jobby). Any ideas on what code I need to add in the Worksheet_Change event just after the new worksheet is automatically created?
I have seen many examples posted here that are close to what I need, but I am not experienced at writing code, so I am not sure how to make the changes to this code that apply to what I need. So I will try to explain what I am looking for & hopefully not be too long winded:
I have an excel workbook that has several worksheets within it - 10 of the worksheets are identical as far as the formulas that are in each of the cells, however, they are all VLOOKUP cells that refer to another excel workbook (used as a "database")which lists all of our projects - there is a cell in each of the 10 sheets that can be changed that will allow that particular worksheet to access the information in the "database worksheet" for the particular project name that is entered in this cell.
There is currently an event worksheet code for each of these worksheets which allows for a picture to be displayed "floating" above cell (L13) based on the project name that is showing in this cell- however it is based on all of the project pictures "living" in each worksheet (the picture that is called up by the project name is displayed while the rest are hidden - as per the formula)- the code is shown below: Option Explicit
Private Sub Worksheet_Calculate() Dim oPic As Picture Me.Pictures.Visible = False With Range("L13") For Each oPic In Me.Pictures If oPic.Name = .Text Then oPic.Visible = True oPic.Top = .Top oPic.Left = .Left Exit For End If Next oPic End With End Sub
However - this option works fine when there are 5 or 10 pictures/projects - but we are looking to grow our project database. So, I was hoping to be able to store the pictures in another location (such as another worksheet or in a file on the server - I would also appreciate input if anyone has an opinion on which would work better?) and have some type of worksheet event code that can be written in to each worksheet that would access the picture in this "central" location and have them appear in cell (L13) of each worksheet based on the project name displayed.
I have 2 worksheets ('pathways', 'pathway events').
'pathways' has unique rows with a unique ID i.e. [Pathway ID] whilst 'pathway events' has the same initial column [Pathway ID] but with multiple values of the same [Pathway ID] value.
If an [Pathway ID] value is selected in 'pathways', I want it to trigger some code which will open a new worksheet and copy the multiple rows in 'pathway events' with the same [Pathway ID] value and paste them into the new worksheet.
Is this possible to do in Excel. I normally use Access and you can have triggered events.
i try with what limited knowledge i have, if you dont mind take a look at the code below, i read your article and added the appropriate line, the code works fine except the msgbox has to be ok'd twice before it exits sub any ideas why?
Private Sub Worksheet_SelectionChange(ByVal Target As Range) Dim rng As Range Dim MyCell Set rng = Range("A2:A100") If Not Intersect(Target, rng) Is Nothing Then With rng For Each MyCell In rng If MyCell = "" Then MyCell.Select MsgBox "Please use this next blank cell" Exit Sub
Is it possible to copy a "Worksheet_change event" macro to a new worksheet by macro? Like when I insert a new worksheet, a certain macro, for example "run macro on data entry", to be already written in its worksheet_change event.
For Each kopSheet In ThisWorkbook.Worksheets If Left(kopSheet. Name, 8) = "Inddata-" Then kopSheet.Copy ActiveWorkbook. SaveAs ThisWorkbook.Path & "" & kopSheet.Name ThisWorkbook.VBProject.VBComponents("Kopier1").Export filNavn Workbooks(kopSheet.Name & ".xls").VBProject.VBComponents. Import filNavn ActiveWorkbook.Close End If Next kopSheet
I copy 6 sheets, named "Inddata-*", and i wan't to copy a module named "Kopier1" with it. I know that i can use an add-in, but that is unfortunately not a good idea in this project. It does export the module "Kopier1", but, it doesn't import it to the newly created workbook!
I have a manually calc'd workbook with the following code
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Me.Range("VAL1CELL")) Is Nothing Then Me.Calculate If Not Intersect(Target, Me.Range("VAL2CELL")) Is Nothing Then Me.Calculate If Not Intersect(Target, Me.Range("CHOICE")) Is Nothing Then Me.Calculate If Not Intersect(Target, Me.Range("$L$36")) Is Nothing Then Me.Calculate
If ActiveCell.Address = "VAL1CELL" Then Range("VAL2CELL") = Range("Y$41")
Everything works as it should other then the part that is
If ActiveCell.Address = "VAL1CELL" Then Range("VAL2CELL") = Range("Y$41")
When the user selects VAL1CELL This is cell B2 and is a drop down, I want VAL2CELL which is C2 and also a drop down to show what is in Y41 (i.e the first name that appears in the drop down...not a thing happens ? is there a flaw to my code ?
change the below code from a worksheet_change to a worksheet_calculate method. and still do the same action. the reason I am changing methods is due to the fact that the validation will not trigger the worksheet_change event to fire. this is my attempt to find an alternative way to fire off the macro.....
Am trying to copy some code from the ThisWorkbook object into about 100 other Workbooks. I know how to Import and Export Modules, but when I export code from ThisWorkbook in saves it as a CLS file. Upon export a new class module is created. I simply want to create code that will automatically copy the code from one VBA project ThisWorkbook object to another VBA project ThisWorkbook.
I have the code to open all the files etc just need to figure out how to import the code from ThisWorkbook.
I ran this code last week and it worked great, but today it doesn't work at all. I have even deleted it, closed Excel and and started fresh. Is there some small thing I'm missing (like hopping on my left foot while entering a code) ...
I've been using these things called ranges, but I'm not even really sure what they are or how to use them effectively. I want to be able to make the following macro only applicable to the range, of anything below F5,G5 and I5.
Private Sub Worksheet_SelectionChange(ByVal Target As Range) If Target.Cells.Count > 1 Then Exit Sub If Not Intersect(Target, Range("$F:$I")) Is Nothing Then Target.Font.Name = "Marlett" If Target = vbNullString Then Target = "a" ElseIf Target = "a" Then Target = "r" Else Target = vbNullString End If End If End Sub
I know how to enable/disable events using VBA code, however is there an option within excel to turn it on/off? My problem is this...
At the beginning of my code I disable events and at the end I enable it again (I need to do this to avoid being caught in a loop). However something is going wrong somewhere in my code and the code stops halfway through. I'm trying to test sections of the code, but I often inadvertently stop the code without enabling the events again. Therefore I can't get my VBA to execute again unless I close excel down and restart. This is a pain as I have to find my place in the code again!
I have these codes in place in my excel file, there is nothing wrong with them at all. Here is the the problem : My superior runs the macros in place in the file almost daily, and when he is done he then closes it and all is well. The macros does things to other files so they are changed in a way that the supervisors like them. I avoided putting macros in these individual files, because of the attempt to make it as simplistic as possible without them being able to affect overall file. The problem happens when he (my superior) accidently makes a change in the primary sheet in the workbook with all the macros, it affects alot of my formulas and macros that are already in place. Within this workbook, it keeps a log of things from the other files results, so I have to have a record of it in the workbook, hence having a save event in place.
The Question: Is it possible to create a macro button, that will allow him to disable the codes below, so that he can close it and open again, so that it doesn't show any of the errors that happens by accident and try to close it again so there is no errors? Basically, I am asking what is the code for this, and where would I place it in.
Private Sub Workbook_BeforeClose(Cancel As Boolean) Dim mylogoff Set mylogoff = Sheet1. Range("A65536").End(xlUp).Offset(0, 1) mylogoff.FormulaR1C1 = "=NOW()" mylogoff.Copy mylogoff.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False Application.CutCopyMode = Fals mylogoff.Offset(0, 1).FormulaR1C1 = "=RC[-1]-RC[-2]" Application.DisplayAlerts = False Sheets("Start Here").Select ThisWorkbook.Save ThisWorkbook.Close End Sub......................
Looking for a Private Sub Worksheet_Change(ByVal Target As Range) code to concatenate cell J, K, E and F cells when both J6 and K6 are selected. The cells start in J6 and K6. When both J6 and K6 are selected, I would like a VBA code to concatenate J6, K6, E6 and F6 in cell L6
(Here is the formula =IF(OR(J6="",K6=""),"",I6&" "&J6 &" "&K6&" - "&E6&" "&" "&F6 I have but looking for a VBA code to accomplish task).
When either J6 or K6 is selected, the code should not concatenate until both cells (J and K) are selected. I would also like a Clear Contents function to clear L6 (or L7, L100, L80 or L13) contents when either J or K cell is deleted. For example, if K value is deleted, the Clear Contents should clean J and L cells contents.
I'm making a macro to show or hide rows depending on whether or not a checkbox is checked. I'm using Wingdings font checkboxes, not actual form controls. The question: My macro can't find the last row of the used range on the sheet. This is in the sheet's code, set to fire when the selection changes.
Normally the line in blue works just fine, but it's not working here. In the attached workbook, the macro thinks the last used row is row 19, when it's actually row 21. What's going on?