A Worksheet OnScroll Event
Oct 30, 2007
There is no such event in excel. Using a timer to constantly monitor any change of the ScrollRow/ScrollColumn of the activewindow is feasible but it is not worth it because of the strain that such a running timer would put on the application.
While playing around with some Controls via the "More Controls" icon on the ToolBox Toolbar, I came accross this ActiveX control named: InkPicture which has an interesting event called InkPicture_Painted and which basically fires every time it receives a repaint message.
I thought , maybe if i place one on the worksheet , the Control paint event would fire when scrolling the worksheet. Guess what: It worked
I embeeded one into the worksheet and reduced its width to a minimum so that it's almost invisible. I streched its height over 1000 rows so it covers a reasonable down/scrolling region.
Ok. Now, before I get too excited about this, there is a problem: Does this InkPicture Control come with all or most Office standard installations like the OWC controls? if so then great. if not, i should just forget about this whole thing. (i am running Office XP XL 2003)
Notice that there is also an annoying prompt upon opening a workbook containing an embeeded ActiveX control. Fortunatly, this can be avoided by adding a reference to the Control library ( MS Tablet PC Type Lib) Programatically , adding the Control at run time and hooking its events in a Class module.
here is a a workbook demo that shows an implementation of this custom Worksheet Scroll Event (it captures the event to prevent the user from scrolling down beyond the visible range ) : http://www.savefile.com/files/1158486
I would appreciate any feedback on this as i would like to know if it works on different machines/XL versions.
View 9 Replies
ADVERTISEMENT
Mar 27, 2009
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?
View 9 Replies
View Related
Jun 12, 2007
In cell A1, I have the month number (eg, 1, 2, 3,). The month number reflects current month and will automatically change with every month. For example, right now it’s 6, next month it will automatically change to 7. Each two columns in Range A10:X20 represents the data from January to December. I want to use a worksheet event to change the background of the current month two columns in the range to yellow color and the two columns in the range will be visible when I activate this sheet.
View 3 Replies
View Related
Jan 10, 2009
looking to only allow a check ("x") in a column for a reconcile - type worksheet. Am I close?
Private Sub Worksheet_Change(ByVal Target As Range)
'Data protection. Only allow "x" in the "cleared" column. If anything else is entered, a message box informs the user
'and the cell contents are cleared.
Dim val As Variant
Dim msg As String
If ActiveCell.Value "x" Then
msg = "You can only enter an X in the cleared column."
ActiveCell.ClearContents
End If
End Sub
View 9 Replies
View Related
May 30, 2009
I would like to run a some code that is only activated if another worksheet in the same workbook is selected and I'm not sure how to achieve it.
View 9 Replies
View Related
Feb 7, 2014
I am trying to run the below code whenever the result of cells (22,x) changes. Cells (22,x) contains a formula.
[Code] .....
View 2 Replies
View Related
Feb 27, 2008
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?
View 14 Replies
View Related
Jul 25, 2009
I have created a chart with four data ranges. I have a check box for the four ranges. If a check box is TRUE the data is shown in the chart. When I check one of the check boxes, I want the CreateChart macro to run, but this is not happening with the code below?
View 4 Replies
View Related
Jan 17, 2007
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.
View 9 Replies
View Related
May 28, 2009
trying to get a worksheet change event to work. Basically the code below calls the time_start procedure when cell J16 downwards is selected.
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Row > 15 And Target.Column = 10 Then
Call time_start
Else
End If
End Sub
However, I am lost from here on....Let me try and explain what it is I am trying to do. This seems so simple if you know how. Each time that the word "Completed" is entered in to a cell from J16 onwards, the cell two columns to the right on the same row is selected and the current date is entered.
If the word "Completed" is deleted, I want the date on that row to be deleted.
I would also like the choices "Completed" and a blank cell to be given in a validation list via a dropdown if possible to avoid occurances of "Complete" etc and mis-spellings but I understand that a bug may stop me from using this functionality. I am running Excel 2002 on a Windows XP Professional OS.
View 9 Replies
View Related
Jan 26, 2010
i need to add a DoubleClick event to about 40 workbooks.
each has 6 sheets and the code will be added to two of them.
i can cycle thru the folders/subfolders and open the correct files.
but how do i put the code into the specific sheets using a program?
View 9 Replies
View Related
Aug 20, 2007
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.
View 7 Replies
View Related
Oct 3, 2007
I'm having trouble copying a macro to a newly created sheet. I do like this:
ThisWorkbook.VBProject.VBComponents("Kopier1").Export filNavn
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!
View 2 Replies
View Related
Nov 21, 2013
i currently have a workbbok that i have a very simple worksheet event macro that will filter a seperate sheets contents to the corresponding entry number. is there any way to make a dynamic event macro that will filter my second sheet depending on what cell is selceted on the first.
for example record 1 on sheet 1. if cell L1 is selected it will filter sheet 2 to to record 1, record 2 on sheet 1, if cell L2 is selected it will filter sheet 2 record 2 and so on. this list of records will continue to grow and i cant think of any way other than what i currently have, which is to make each filter macro for every cell.
is ther a better way example of CODE HERE
VB:
Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
If Target.Address = "$L$5" Then
Call Filter1
[Code]....
View 2 Replies
View Related
Jun 22, 2009
I wrote a worksheet activate event (for wrksht1). It reads a list of customer inputs found on wrksht1 then parses these inputs into 'like' lists and pastes the results into a wrksht called ADIM. ADMIN is kept well hidden so our customer cannot mess with it. These parsed lists are then used as validation data with the drop down menus applied to cells found on wrksht2. So to recap, inputs on wrksht1 appear as drop down values for cells found on wrksht2. Here's the problem. The worksheet activate event is triggered whenever wrksht1 is activated and since the code changing the focus away from this wrksht and then back to it, it appears to enter an endless loop. At least I think that is what is happening. Is there a way to programmatically deactivate the event so that when focus returns to wrksht1 the event does not trigger and cause an endless loop? and then reactivate so the event triggers then next time the user changes focus.
View 2 Replies
View Related
May 7, 2013
I have the below vba and would like to have the '''event calculated ''' on any event on the worksheet. Right now it only update if updating the val1 thru val6 cells. How can i get the worksheet to update on any event or change on the sheet?
Private Sub Worksheet_Change(ByVal Target As Range)
On Error Resume Next
fr = Range("a65536").End(xlUp).Row
Set Rng = Range("a2" & ":n" & fr)
If Intersect(Target, Rng) Is Nothing Then Exit Sub
[Code] .......
View 2 Replies
View Related
Mar 6, 2007
I have looked at the threads concerning cell change events but cannot find a solution to my situation. I have a worksheet with a cell using a validation list. I wish to exicute a procedure whenever the dropdown list is changed in that one cell. Everything I have seen in the Worksheet event threads is evaluating the contents of a cell and I am attempting to exicute if the cell changes.
View 2 Replies
View Related
Aug 22, 2007
I have a spreadsheet with a table of values in range E5 to T158.
A macro populates the table by looking up values on other sheets in the book. If the macro finds a value in the lookup for Row 7 of any column (ie E7,F7...T7) it populates the rest of the column with that value (E7 value gets pasted to E8:E158) THEN it protects the cells it pasted (E8:E158).
If the macro does NOT find a value for row 7, it simply skips it, leaving it blank, and continues to row 8 until it reaches row 158 of each column E to T.
I want to give the user flexibility with these values. So if the user either deletes E7 or changes the value of the contents in E7, I want to unprotect the cells of rows 8 to 158 for that column.
I have created a
Private Sub Worksheet_Change(ByVal Target As Range)
in the private module for that sheet below. I thought it was working but it isn't doing anything when I change or delete the value in Cell E7 for example. Please help!
Private Sub Worksheet_Change(ByVal Target As Range)
'Do nothing if more than one cell is changed
If Target.Cells.count > 1 Then Exit Sub 'Or IsEmpty(Target)
View 5 Replies
View Related
Nov 22, 2011
I'm trying to create a worksheet change event macro that will change the colour of the cell when you update the value in that cell.
I have column C with 140 rows and when one of the cells in the column is changed by the user, I need the same cell to highlight in yellow. The highlight would then be removed once the user has acted on the change in the value, and that'll be done in another macro.
I understand I need a worksheet change event macro in the specific sheet and need the following code for yellow:
Code:
.Interior.Color = RGB(255,255,0)
, but any further I get stuck as it involves 'target addresses'
View 2 Replies
View Related
Oct 1, 2013
combine two Worksheet Change event macros into the one macro? The macros are listed below.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)On Error GoTo exitHandler
Dim rngDV As Range
Dim lRow As Long
Dim lCol As Long
[Code]...
exitHandler:
Application.EnableEvents = True
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("O:O")) Is Nothing Then
Application.EnableEvents = False
[Code]...
View 7 Replies
View Related
Nov 30, 2006
I have the following code that should pop up a message when column E is left blank when "other" is typed into column D. But I cannot get it to work.
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rng As Range, LastRow As Range
Dim x As Integer
If Target.Count > 1 Then Exit Sub
Set rng = Range("F:F")
If Intersect(Target, rng) Is Nothing Then Exit Sub
If Target = "" Then
For x = 1 To 5000
If Cells(x, 4).Value = "Other" And Cells(x, 5).Value = "" Then
Answer = MsgBox("If other, please state", vbOKCancel, "CONFIRMATION")
End If
Next x
End If
End Sub
View 9 Replies
View Related
Mar 28, 2007
I have the following code that 'sort of' works.
Private Sub Worksheet_Change(ByVal Target As Range) ...
View 9 Replies
View Related
Jul 31, 2008
In Col D of my spreadsheet, I have a list of security codes, in this list there is a security code "all", i need a macro that will add 1 to the code, so it reads "all1", now i need the macro to run as soon as new data is pasted to sheet "Lending", the ranges in Col D do change on a daily basis therefore cell reference for security codes is not fixed.
Can this be achieved? ............
View 9 Replies
View Related
Mar 5, 2009
I am using Excel 2007, and I have a macro (that is working) that I would like to run whenever there has been a new selection in a dropdown list on my worksheet. I have done this many times before in other workbooks, and I have always used:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
End Sub
To my knowledge this should trigger the macro when the dropdown selection changes. However, this time it is not working. The macro runs fine manually, but it does not run when the dropdown selection changes.
View 9 Replies
View Related
Apr 25, 2009
This is the code on the Worsheet Change event.
Private Sub Worksheet_Change(ByVal Target As Range)
'Define the RMAs range and count the RMA ships. Do the rest of the math based on this calculation.
Dim intRMACol As Integer, EndRow As Integer, intRMAShips As Integer, LastCol As Integer
Dim rngRMAs As Range, rngHome As Range, sht As Worksheet
Set sht = ActiveWorkbook.ActiveSheet
Set rngHome = Cells(1, 1)
rngHome.Activate
EndRow = Range("A" & Rows.Count).End(xlUp).Row
intRMACol = Cells.Find(What:="RMA#", After:=[A1], SearchOrder:=xlByColumns, SearchDirection:=xlNext).Column
Set rngRMAs = rngHome.Offset(1, intRMACol - 1).Resize(EndRow, 1)
rngRMAs.Name = "RMAs"
rngHome.Offset(1, LastCol + 1).Formula = "=COUNTA(RMAs)"
intRMAShips = rngHome.Offset(1, LastCol + 1).Value
rngHome.Offset(1, LastCol).Formula = "=SUM((" & EndRow & " - 1) - " & intRMAShips & ")"
rngHome.Offset(1, LastCol + 2).FormulaR1C1 = "=SUM(RC[-2] : RC[-1])"
End Sub
I keep getting stuck when trying to set the intRMACol variable. I have used the code all over the place, but only in Modules, never on a worksheet event. EndRow, the variable right above, sets correctly so I don't get it.
Also, do I have to define the Target variable? Am I going about this the right way? I basically want three formulas to calculate when any change is made on the worksheet.
View 9 Replies
View Related
Nov 9, 2009
I'm trying to insert a worksheet change event using VBA. I have this sample code from here -
http://www.cpearson.com/Excel/vbe.aspx
Sub CreateEventProcedure()
Dim VBProj As VBIDE.VBProject
Dim VBComp As VBIDE.VBComponent
Dim CodeMod As VBIDE.CodeModule
Dim LineNum As Long
Const DQUOTE = """" ' one " character
Set VBProj = ActiveWorkbook.VBProject
Set VBComp = VBProj.VBComponents("ThisWorkbook")
Set CodeMod = VBComp.CodeModule...................
View 9 Replies
View Related
Aug 4, 2006
I have this code working fine. It applies conditional formating to two rows ((K3:K65) and (J3:J65)) and checks when a value changes in row B to reaplpy the formatting. I'd like to had add more columns to it. It would have apply the same conditonal formatting on rows ((O3:O65) and (P3:P65)) but when a value changes in row (N3:N65)
So basically, I want to keep the first working part of the code and have it to check at more rows with a different reference for the conditionnal formatting.
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rng As Range
Dim rngJ As Range
If Target.Count > 1 Then Exit Sub
Set rng = Union(Range("B3:B65"), Range("J3:J65"))
If Intersect(Target, rng) Is Nothing Then Exit Sub
Set rngJ = Range("K" & Target.Row)
Select Case rngJ.Value
Case ""
rngJ.Interior.ColorIndex = xlNone
rngJ.Offset(0, -1).Interior.ColorIndex = xlNone
Case Is >= 20.............................
View 2 Replies
View Related
Aug 29, 2006
I am trying to make a macro run automatically based on info entered in a cell. The problem is I need this code on at least three separate sheets in the work book. It doesent work when I try to use the same basic code. The code I am using is below.
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Dim lLastRow As Long
Dim rgArea As Range, rgCell As Range
Dim COL_B As Integer
COL_B = 2
Dim COL_X As Integer
COL_X = 24
Dim ROW_FIRST As Long
ROW_FIRST = 5
' Find the last row of date in the "Approved" worksheet
lLastRow = FindLastRow(SZ_WS_APPROVED, COL_B)
' Set a reference to the changed cells in column X
Set Target = Intersect(Target, Range(Cells(ROW_FIRST, COL_X), Cells(lLastRow, COL_X))).........................
View 5 Replies
View Related
Aug 31, 2006
Private Sub Worksheet_Change(ByVal Target As Excel. Range)
Dim S As String, X As Variant, n As Long
If Target.Column <> 3 Or Target.Cells.Count <> 1 Then Exit Sub
If IsEmpty(Target) Then Exit Sub
S = Target.Text
On Error Goto Reset
n = Application.Substitute(S, "-", "")
On Error Goto Reset
Application.EnableEvents = False
X = Application.Match(n, Workbooks("Database.xls"). Sheets("Products").Range("B1:B14000"), 0)
If IsNumeric(X) Then
Target.Offset(0, -1) = Workbooks("Database.xls").Sheets("Products").Cells(X, 1).Value
Else............................
But each time i add it in, it ether's turns off the second statement and second works or vice versa. How can make both codes work at the same time without conflicting each other.
View 3 Replies
View Related
Sep 1, 2006
I am trying to do a conditional format of 0 to 2 is red, 3 to 4 is yellow and 5 is green. However I also need to have a cell that is blank to remain white and this is the part I am having problems with.
I found the following code since I cannot use the standard conditional formating in excel since it needs 4 conditions.
Private Sub Worksheet_Change(ByVal Target As Range)
Dim icolor As Integer
If Not Intersect(Target, Range("H3:H12")) Is Nothing Then
Select Case Target
Case 0 To 2
icolor = 3
Case 3 To 4
icolor = 6
Case 5
View 7 Replies
View Related