Worksheet Change Monitoring 2 Cells & Calling 2 Function

Apr 30, 2007

Is it possible to use the Worksheet_Change command to monitor 2 different cells in the same worksheet and call a different procedure depending on which cell is changed. i.e. if cell A1 is changed do this, if cell a2 is changed do that

View 9 Replies


Excel 2007 :: Monitoring Change In Certain Range At Worksheet?

Jul 9, 2012

I wish to monitor a change in a certain columns at some worksheets. I have - after having consulted John Walkenbach' fantastic book Excel 2007 Power programming with VBA - understood how I do to monitor a change in specific worksheet, by using the Intersect-function in the change-event on that particular worksheet. That works fine.

My situation is that I have an application that I start out with a certain number of workheets in a workbook, and in the course of the work that the application does, it now and then adds worksheets, and these worksheets I would like to monitor for change in a special column. I know, by looking at the names of the worksheets which ones of those in the collection that I want to check.

I therefore used, not the Worksheet_Change event but the Workbook_SheetChange. It doesn't work quite well. I guess my question for now would be:

The call to this event looks like this:

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)

1) How - in what way - should I use the first argument, the "Sh as Object"? Can I/Should I give it a name?

The error message I get when I use an instruction like this:

If Not Intersect(Target, Range(M:M)) Is Nothing Then
'Do Stuff
end if

The method 'Intersect' in the object '_Global' failed

(M is the column that I want to check)

View 4 Replies View Related

Calling Function From Worksheet With Nonconcurrent Range

Sep 26, 2007

I have a User Defined Function (for finding the next minimum value in a range) that is not working for nonconcurrent ranges when called from within a worksheet. It returns #VALUE!

This works: =nextmin(A11:A17)
This does not work: =nextmin(D13,E13,F13,F16)

However calling the function from within vba works:

View 9 Replies View Related

Monitoring Sheet For Change In Cell?

Apr 8, 2014

If the user enters a numeric value in Range ("B" & Rows.Count).End(xlUp).Offset(1), I need the code to copy the formulas in Range ("A12,C12:V12") to Offset row If there is no user entry in Range ("B" & Rows.Count).End(xlUp).Offset(1) then nothing should happen.

This should be monitored in sheet at all times.

I`ve done som research and think the code must be entered as a Private Sub Worksheet_SelectionChange(ByVal Target As Range) sub?

View 13 Replies View Related

Worksheet Change To Function To Add Text To Cell Which Initially Triggered Change

Jan 10, 2014

i have some existing code which is trigerred when anything is input into column c. The code then adds various information in another three columns. One of which pastes a vlookup formulae, and i would like this forumlae pasted into the column c cell which i initialy edited, in order to remove the requirement for one additional column.

The existing code i have is:

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Dim MyText As String
MyText = Environ("username")
If Target.Cells.Column = 3 Then
With Target
If .Value "" Then
.Offset(0, 2).Formula = "=VLOOKUP(D:D,'P:TAOffshoreTAOffshoreTreasuryRecsGeneralCommit ID''s for control Sheet - Do not move or delete[commit ids - DO NOT DELETE OR MOVE.xls]Sheet1'!$A$1:$B$65536,2,0)"


I have tried changing the offset to (0,0) or changing the offset to 'target = ', which does add in the vlookup but then the macro debugs at the 'If .Value "" Then' code?

View 3 Replies View Related

Worksheet Function: Change C2 To Change To Activecell Column + Row 2

Jun 23, 2006

How would I add this formula as a worksheet function with VBA. I can't see INT, MOD or Year in VBA. Also want to change C2 to change to activecell column + row 2.

=INT(((C2-1461)- SUM(MOD( DATE(YEAR(C2-MOD(C2,7)+3),1,2)-1461,{1E+99,7})*{1,-1})+5)/7)

View 4 Replies View Related

Calling Function That Acts On Matrix Range Within Another Function

Jul 23, 2013

I have a function

Function f1(Matrix As Range)
'Does something and returns f1 = a double
End Function

And a second function which defines and constructs a matrix of doubles to use as an argument in f1 to return a double:

Function f2(dD As Double)
Dim MatrixRed() As Double
Redim MatrixRed(1 To dD, 1 To 10)
For i = 1 To dD
For j = 1 To 10
MatrixRed(i, j) = i * j
f2 = f1(MatrixRed)
End Function

I get an output error (#VALUE). I think it has something to do with MatrixRed not being a range anymore?

View 2 Replies View Related

Calling A Function

May 1, 2007

I guess I just don't understand the basics of calling a function. I have the following function in a standard module:

Function CleanUp(ws As Worksheets)
ws. Range("A2:P100").ClearContents
End Function

I have this code in a worksheet module:

Sub Trying_to_call_a_function()
CleanUp (ThisWorkbook.Worksheets("Month End"))
End Sub

But when I run the routine that calls the "CleanUp" function, I get the message: "Object doesn't support this property or method." I have tried changing the Function to this: CleanUp (ws as Worksheet) [instead of (ws as WorksheetS)]. Yet, this does not change anything.

View 3 Replies View Related

Worksheet Change Function With VLookup?

Oct 21, 2013

I am attempting to write a bit of code so that Vlookup is called when a particular cell in my spreadsheet is populated.

Although it seems to be working, it is only pulling in the data in row 1.

An example of the code is below.

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Row 1 Then
If Target.Column = 2 Then


View 1 Replies View Related

Calling A Function In A Procedure

Feb 2, 2010

I need to extract the filename “My Excel File” from Worksheets(“Sheet1”).Range(“A1”), whose value = C:Documents and Settingsuser1DesktopMy Excel File

I found on Chip Pearson’s site a Function TrimToChar which, using SearchFromRight and a TrimChar of “” will trim OFF the filename “My Excel File”, leaving the Path.
But, I think I could use his function to tell me the number of characters in the Path and then use that to extract the remaining characters from the total character length (Mid Function)

Problem is, I don’t have a clue how to call a Function in VBA to work on Worksheets(“Sheet1”).Range(“A1”). How do you set the InputText , TrimChar, & SearchFromRight?????

(eventually, this will be in a loop, where I extract the filename from a Dynamic Named Range (list) in Column A)

View 3 Replies View Related

Calling A Custom Function Within VBA

Sep 9, 2009

I have created a custom Function in excel. I would like to create a custom button so I can run this funtion with a Click of a button unstead of typing it in or clicking on the insert function button. I am not sure if this is possible to have VB call a custom function. Below is my VB for the Custom Function. I basically want the custom button to open the formula in excel.

Public Function CreateFlexstring(Company As String, Cost_Center As String, _
Division As String, Geography As String)

CreateFlexstring = Company & "-" & Cost_Center & "-" & Division & "-" & Geography

End Function

View 9 Replies View Related

Calling Function From Add-in Causes Crash

May 19, 2009

I have an add-in that has one function in it. We plan on adding more, but not until we figure out what's happening. The one function is a Select- Case statement...send the function an alpha code and it returns a numeric account number based on the alpha. About 20 "cases" in total. The add-in loads fine and the function works fine from a spreadsheet cell. However, we're getting differing results when we try to access the function from VBA code. I've been able to duplicate this several times on three different computers on our network.

The VBA code will work fine, several times and then on the 4th or 5th attempt it will cause Excel to crash ==> "Microsoft Office Excel has encountered a problem and needs to close. We are sorry for the inconvenience." If I " recover" the crashed file, comment out the line to call the function, run the program again it works. Then I can un-comment the line, re-run the program and it works fine again for 4 or 5 more attempts. I've tried running the Repair tool already. I've also copied the code out of the spreadsheet and started a new file. The same errors 4 or 5 times and then crashes the program. The add-in and the spreadsheet exists on networked drives.

View 3 Replies View Related

Change Empty Cells To Blank Cells (need To Use Skip Blanks Function)

Mar 8, 2014

I have a spreadsheet where a column has many cells being empty and others with values. I need to use copy-paste skip blanks to another column so it only overwrites cells that contains values. BUT The cells in the column appears to be empty, not blank, when I try use the copy-paste skip blanks it doesnt work. However, when I press delete in every empty cell the copy-paste skip blanks works for those cells.

Do you got a fast method to make all the empty cells blank?

View 4 Replies View Related

Calling Value From Sheet And Send It Back In Concatenate Function

Jul 23, 2014

how to properly write this kind of commands!

v_1 = Sheets("WB_Input").Cells(i, 2) 'It's gonna be a numeric value like 10
v_2 = "E"
v_3 = Sheets("WB_Input").Cells(i, j) 'It's gonna be a numeric value like 12
Sheets("WB_Output").Cells(i, j) = "=CONCATENATE(" & v_1 & "," & v_2 & "," & v_3 & ")"

Thing is once I look at the WB_Output Sheet what I see is an error and the cell shows this: =Concatenate(10,E,12)

So logically the problem is that I need to make it show up as =Concatenate("10","E","12")

Btw, I can't just put v_1 & v_2 & v_3, cause Excel understands "E" as exponential!

View 1 Replies View Related

Excel 2000 :: Macro Calling Unrelated Function?

Jun 9, 2014

the macro works fine until it executes the paste values. At that point, the macro jumps to the "CountThem" function which is located in another workbook. The data that I am copy/pasting is in no way connected to any cells that are using that function. Although, other values in the workbook are passed down from data that uses that function.

I am still in the dark ages using Excel 2000.

This is the code for my macro.

Sub Current_to_Raw()
' Current_to_Raw Macro
' Macro recorded 2/12/2014 by


View 2 Replies View Related

Excel 2003 :: Upgraded To 2007 And Worksheet Change Function Does Not Work

Oct 10, 2011

I recently upgraded from Excel 2003 to 2007, and the worksheet change procedure that i have embedded in my worksheet no longer fires when the criteria are met. If and if I fix it to work in 2007, will it still work in 2003?

Here is my procedure:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim rngCell As Excel.Range
If Not Intersect(Target, Range("C19:R19")) Is Nothing Then
For Each rngCell In Intersect(Target, Range("C19:R19"))
If rngCell.Value = "BLACK" Then
MsgBox "Please select a shading style", , "Shading Style Required"
End If
Next rngCell
End If
End Sub

View 2 Replies View Related

Calling Codename After Creating Worksheet?

Mar 7, 2013

The below example creates a new worksheet and tries to get the new worksheets codename. The problem is when I run the code, I can't seem to be able to pull the codename from the newly created sheet (ie Cell A1 = "" instead of "sheetx").

Sub test()Set mysht = ThisWorkbook.Worksheets.Add    x = mysht.CodeName    mysht.Range("A1") = xEnd Sub

View 4 Replies View Related

Return From A Macro To The Calling Worksheet

Jan 6, 2009

how I can go back to the worksheet I was in before I branched off to work in another worksheet via a macro?

I know you can tell the macro which worksheet to go to, but not sure how to get vb to remember where I was and return to the same sheet (or even cell).

View 9 Replies View Related

Looping Through Each Worksheet And Calling A Macro

Jan 13, 2010

I had create a few macro with the macro name the same as the worksheet name.

How can i create another macro to loop through all the worksheet and if there is any data in Cell A1, it will call the corresponding macro. If there is no data, it will go onto another worksheet.

View 9 Replies View Related

Worksheet_Change Macro (run Any Time There Is A Change In Any Of The Cells On The Worksheet)

Jun 24, 2009

determine the coding for a worksheet_change macro for the attached spreadsheet? I've got a macro set up in the worksheet and would like it to run any time there is a change in any of the cells on the worksheet.

View 4 Replies View Related

Excel 2007 :: How To Change All Reference Cells In Worksheet

Aug 26, 2010

Here is my situation:

I created one worksheet called: Assumptions. In this worksheet I have 6 different columns representing 6 different cases.

I have completed the first case in a different worksheet called: WL. I would like to copy this case/worksheet WL and be able to change all the reference cells used in case#1: WL to case#2: FA. So all the cells used in my Assumptions worksheet were in the B columns for case 1: WL, for case 2: FA they will all be in the C column, same row, different column.

Any quick way to do the changes?

My case #1 worksheet as over 10 000 formulas, I really don't want to change each and every formula.

I was thinking there was a way to highlight ALL the reference cells used in my Assumption worksheet, so I would have had to drag from B to C cells, only 50 cells. But I can't find it.

View 12 Replies View Related

Worksheet Change Not Firing When Pasting To Multiple Cells

Mar 17, 2014

The code below will put "Some text" into column B when data is pasted into column D. This only works when copying data into one cell. If I copy into multiple cells of column D then the code does not run at all.

[Code] ......

View 4 Replies View Related

VBA Worksheet Change Insert Line And Format Particular Cells?

Nov 8, 2013

what I am looking to do is when in colum AA a cell changes to "Drawdown" I'd like the cells in column A:D,F,H:L,N:Q,S:Z on the same row to grey out and a line to be insert below the cell that was changed, if it selects "Fee" , cells in A:D,F,H:L,N:Q,S:Z on the same row.

I have writen the following butit seems rather cumbersome and I can not get the insert line to work.

Sub Worksheet_Change(ByVal Target As Range)
Dim WatchRange As Range
Dim IntersectRange As Range
Set WatchRange = Range("AA1:AA500")
Set IntersectRange = Intersect(Target, WatchRange)


View 6 Replies View Related

Worksheet Change Event For Multiple Target Cells?

Jan 20, 2014

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.

Private Sub Worksheet_Change(ByVal Target As Range) If Not Intersect(Target, Range("G2")) Is Nothing Then


View 3 Replies View Related

Target.Cells Is Counting In Worksheet Change Event

Nov 6, 2006

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

View 2 Replies View Related

Change A Worksheet Tab Colour Dependant On The Contents On A Range Of Cells?

Mar 24, 2014

I have a worksheey of data and i would like the tab to be a certain colour dependant on the the contents of a range of cells within that worksheet is that possible. i know i need to use VBA and it cna be done based ont he contents of one cell.

So for example i have a sheet of people i am awaiting payment from, based on the last column " bill paid" i want the tab to be Red if there are any blanks in this column/ range and go green when all the cells in the column/ range are filled with "y"

View 5 Replies View Related

Make Worksheet Calculate Event When Range Of Cells Change?

Feb 15, 2014

I have the following code that I would like to trigger when cells B26:U26 change to something other then 0 due to a formula? How was I make this happen?

[Code] .....

View 4 Replies View Related

Create A Macro For A Monitoring System

Jan 7, 2009

I have no experience with macros at all but i need to create a macro for work that will keep the original data entered but work out the difference between new data collected each day ...

View 10 Replies View Related

Workbook With Userform - Monitoring Data Entry

Mar 17, 2014

I have a requirements to do a simple monitoring data entry. Composed of 1 admin and 10 users. These 10 users are assign to a different lines basically every lines have assigned user.

These 10 user will do a data entry. once they are done on the data entry the Admin will update those entered by the users based on ticket number and the users can browse those updated records.

Every users per line have assign ticketnumber that start in "L1"&YY&MM "-"001" this compsed of lines + year+month and numbers.

For the users side. Right now i have already created a workbook with userform to perform data entry by user (samplefor line1 and line2 user).

It has also a viewing form to view by the users if its already updated by the admin. i put also an events if the admin work book is open by other user they cannot access the workbook.

For admin side. I created also a userform for updating the records entered by the users to update records admin will enter ticket number to textbox.

This is the reference to find and search those records that belong to a particular ticket number and lines which will be updated by the admin.

Right now, I am doing records consolidation for both user and admin records. I have a button for both admin and userlines to perform consolidation. Once the user entered the records admin will capture those records and copy to the workbook used by admin to perform update. Then once the admin perform update the user will capture those updated by admin and copy to the workbook under the user.

Basically they have separate workbook for their entry and database.

Right now I encounter some issues which I think this will affect the integrity if records. Sample like once i perform consolidation it create duplicates records.

View 5 Replies View Related

Monitoring InputBox Input For Illegal Characters

Sep 28, 2007

I have an input box that takes in a file name. Obviously, sometimes people put in illegal characters which can't be used in a file name and I need to deal with this. I can check the variable once they have pressed enter but is there a way to check it as they type it in?

It would be very nice to either have nothing happen if they type in a slash or for a msgbox to pop up, as it does in Windows,

View 9 Replies View Related

Copyrights 2005-15, All rights reserved