Custom Functions Show #VALUE! After Macro Has Run

Aug 20, 2008

Recently I found this forum through a Google search along with the perfect solution to a problem I was having finding and replacing text based on a table of replacement values. Here is the thread:

Multiple substitute or replace text using a table

I incorporated the SuperSub function that steveorg developed as a result of that thread into my worksheet by creating a new module and pasting the following code into it:

Function SuperSub(OriginalText As String, rngOldText As Range)
Dim cel As Range
Dim strOldText As String, strNewText As String
' loop through list of old_text used in substitute
For Each cel In rngOldText.Cells
strOldText = cel.Value
strNewText = cel.Offset(0, 1).Value
OriginalText = Application.WorksheetFunction.Substitute(OriginalText, strOldText, strNewText)
Next cel
SuperSub = OriginalText
End Function

It works like a charm as a formula, but I also have a macro in the same workbook that, as soon as it selects the sheet with the formula, calls the SuperSub function and starts executing the code as a macro (even though there is no call to this routine in the macro). The macro ran just fine before incorporating the function into my worksheet.

The formula looks like this: =TRIM((supersub( UPPER(E2),rngSubst)))
If cell E2 contains the string "101 North Main Street, Apartment 5", it would return "101 N MAIN ST APT 5"

Here is the macro:

Sub Import()
'
Sheets("Shoebuy FTP").Select
Range("A2:R200").ClearContents 'This is where it jumps to Function SuperSub(OriginalText As String, rngOldText As Range)

The function runs for every occurrence of the formula in the worksheet, and when it is finished, all of the cells containing that formula show a value of "#VALUE!". I should mention that it does not change the formula at all, but I then have to highlight each cell that contains the formula, press <F2> to edit, then <ENTER> to get it to display the correct results again.

It is probably some stupid little thing that I didn't do when I created the function, but I can't figure it out. I have written numerous macros, but this is the first time I have ever created a custom function.

View 5 Replies


ADVERTISEMENT

Custom Transferable Toolbar Of Custom Functions

Sep 2, 2008

I want to be able to create a range of VBA userforms to quickly perform long tedious tasks. I want these userforms to be accessed from a nice tidy toolbar.

I have done this and it looks nice and works well. What I would like to be able to do is have my custom toolbar of userform controlled functions be transferable so that if someone else wants my toolbar and attached functions they can install it easily much the same way you can do with an add in.

Is this sort of thing possible or does it require them to manually install all my userforms, modules and toolbar? If it is possible what sort of things should I be looking at?

View 9 Replies View Related

Show Custom Error Message If Opening Workbook Macro Code Fails

May 17, 2008

I cannot figure out how to get my error handler to work, or actually, not work. It seems to work fine when there is an error, but the code still gets read even when there was not an error. Basically, I am trying to open a file, which may or may not be there. When it is not there I want a message to pop up informing the user. However, when the file is there and it opens, the error handler still gives the message box. Any ideas what I am doing wrong?

Private Sub btnOK_Click()
Application. ScreenUpdating = False
Dim LCSfile As String
LCSfile = frmSelectFile.Listbox1.Value
On Error Goto ErrHandler
Workbooks.Open Filename:=sPath & sDate & "" & LCSfile & "QUANT.CSV"
ErrHandler:
MsgBox ("File is not quantitated. Please select another file.")
Application.ScreenUpdating = True

End Sub

View 2 Replies View Related

Custom Functions

Dec 3, 2008

I am writing some custom functions to be saved in an Add-In file, but am having trouble saving named ranges. I would like named ranges in the Add-In file to be available in other spreadsheets. Is there a way to do this? Or is there a way to take a range from Excel and save it into a globally available named range using VBA?

View 9 Replies View Related

Load Custom Functions In An Add-in

Nov 28, 2006

I have created some user defined functions and have associated them to a custom category. To simplify things, I wanted to add these functions and the custom category macro to an Addin I already have installed for all my employees. How do I get the the custom category macro to excecute? It should run as soon as excel is opened...but I am not sure what event should be used and where is it installed?

View 2 Replies View Related

Custom Functions Multiple SUMIF

Dec 5, 2008

I am trying to create a custom function to act much like the database capabilities of excel in summing a column based upon multiple criteria of other columns. First, before I get too far, does anyone have an already built custom VBA function that will accomplish this? I find that using the built-in database functionality in excel is VERY slow!

Anyways, I am trying to pass an argument that contains multiple ranges (much like you can do with the SUM() function):

=MultipleSUMIF("E11:E14, F11:F15", "A1, E1", G11:G14)

The first set of arguments is the ranges that I need to look through. The second set of arguments is the values that I need to search within the first two ranges. The third argument is the column that I need to perform a SUM function on.

Instead of doing this, how can I create a function that will allow me to say, "Add another criteria range/value" and it will add another criteria to the list. I am currently passing a string, and that is not ideal, obviously.

View 9 Replies View Related

Custom Button With 2 Sorting Functions

Mar 21, 2007

I am trying to create a custom button in Excel that will sort on two different columns. One column has $ Sales and the other has Unit Sales. So you can click on the button and it will sort by $ Sales and if you click the same button again it would sort by the unit sales. I'd also like the text on the button to reflect what option the data would be currently sorted by. I am able to do one of these macros and assign it to the button, but can't figure out how to get both sort options assigned to the same button. I have had outside people send spreadsheets to me with this but can't figure out how they did it.

View 2 Replies View Related

Prevent Custom Functions From Running Simultaneously?

Jul 31, 2014

I have this excel file with some functions inside a Pivot Table, which use a year value as filter (the value comes from a report filter field) and data from a different spreadsheet to calculate a percentile value ... I created custom functions to replace the excel functions, passing the values as parameters.. The problem is now that when we refresh the connection (Refresh All button under DATA tab) the cells that contain the values returned by the custom function lose those values (go blank) In order to get the values I need to select the filter value again, while when I was using the normal PERCENTILE function the values would always refresh normally

Now... I think the problem might be related to the fact that the spreadsheet in question calls 5 different custom functions at the same time.... and, those 5 function call another at least two more helper functions... so, maybe this recurrence in calling the functions is causing the thing to break up

Is there a way I can prevent this from happening? Maybe put some flag or something that will cause the functions to be executed one by one, and not all at the same time?

View 2 Replies View Related

Custom Functions Causing Slow Calculations

Jan 11, 2010

I have a spread sheet that contains many user defined functions from a 3rd party provider that downloads financial data from an external database. Often not all of the data is required by the user, and as the UDF's take a long time to calcuate, i'd like to provide the ability to easily switch them on and off. Originally I had been looping through cells and either adding an apostrophe in front of the = or removing it. However running this loop is very slow.

I found this thread
(Optimize VBA Loop For Inserting Formula)
and adapted it to convert formula strings (with ' in front) to formulas in a single pass by setting:

myRange.formula = myRange.value. This works very well. I can't, however, work out how to go back the other way in a single pass. Have tried: myRange.formula = "'" & myRange.formula. This works for individual cells, but not for more than one at a time.

View 3 Replies View Related

Efficiency Of Custom Functions (UDF) Compared To Standard/Native Formulas

Sep 30, 2006

Assume I have a sheet consisting of 50 rows with 3 columns of figures. A fourth column contains a formula to calculate values, eg A1+B1+C1, on each line/row. I could enter A1+B1+C1 in the first cell and Copy, Paste to the other 49 cells. Alternatively, I replace A1+B1+C1 with a UDF.

Is there any difference in performance with using a UDF compared to using the long-hand/standard approach, or is it just a question of convenience? After all, both are doing the same operation with the same calculation.

View 5 Replies View Related

Show Data Table - Functions Not Enabled

Mar 27, 2014

When I select anything under the Data Table drop down nothing happens. It is like none of the functions are enabled?

Data Table Picture.png

View 2 Replies View Related

Stop Functions Running While Show / Hide Columns

Nov 28, 2011

I have a couple of functions running in my workbook, and for no reason that I can see, when one of them runs during a simple macro I use to show/hide some columns, the worksheet vanishes. Is there a way to stop all functions running while I show/hide columns?

View 5 Replies View Related

Sheet Custom Properties Show Up

Dec 9, 2006

See custom document properties for a give workbook by using File, Properties but where do sheet custom properties show up.

View 9 Replies View Related

Show A Custom Date Formate

Feb 8, 2007

hi i have a formula in a module that show a date as such

"ddd d" and this shows up as say "fri 6"

how can i get it to show up "f 6" or maybe "fr 6" and not have to use the whole three letters

:o

View 9 Replies View Related

Show Custom View Upon Exit

Sep 26, 2008

I am trying to set a custom view when exiting, but I keep getting runtime error 424 saying an object is required. I am attempting to unprotect the sheets, check the value of an option button, set the custom view based on that value, and then protect the sheets. Please keep in mind that the user may or may not be on the sheet containing the option button when exiting. Here is the code I am having trouble with.

Private Sub Workbook_BeforeClose(Cancel As Boolean)

Call UnprotectSheets 'Unlock to set option button value

With Worksheets("Customer_Info")
If btnExistCust.Value = True Then
ActiveWorkbook.CustomViews("Sales_Exist").Show
Else
ActiveWorkbook.CustomViews("Sales_New").Show
End If
End With

Call ProtectSheets 'Call the sub before closing

End Sub

View 6 Replies View Related

Display/Show Custom Error Message

Aug 31, 2006

I have a userform with a combobox (cmbSearch) , a textbox (textbox1) and a listbox (listbox1)....and a commandbutton (cmbFind). This userform is used for searching records in my worksheet....where user selects a "Search By" category from the combobox and then enters relevent text search criteria in the textbox....and all the search results are shown in the listbox. This part works fine untill someone tries to search a "non-existent" record. e.g. a customer name thats not in the database and it gives an error. I would incorporate in my code to have a Message box pop up on these type of searches saying "textbox1.value Not Found!" insetad of error message.

Private Sub cmbFind_Click()
Set c = Range("a65536").End(xlUp).Offset(1, 0)
'write userform entries to database
Dim DataSH As Worksheet
Set DataSH = Sheets("ComplaintData")

With DataSH
.Range("L1").Value = cmbSearch.Value
.Range("L2").Value = TextBox1.Text
.Range("N1"). CurrentRegion.Clear
.Range("A1").CurrentRegion. AdvancedFilter Action:=xlFilterCopy, criteriarange:=.Range("L1:L2"), copytorange:=.Range("N1")
End With
lstSearch.RowSource = vbNullString
lstSearch.RowSource = "outdata"

End Sub

View 5 Replies View Related

Enter Custom Date Range To Show Data

Dec 10, 2008

I took an Excel course in college but am a bit rusty. I have a customer database that I created and I would like to see certain things after entering a date range that I specify. I uploaded a small excel sheet to show my database and what I'm looking to do. Basically I would like to enter a date range and see these answers:

Total Orders in that date range
Total unique orders in that date range
List of customers (name included) who ordered more than once in that date range

The only columns of data I need to use are: firstname, lastname and orderdate.

View 4 Replies View Related

Custom Number Format :: To Contain (and Show) Both An Interger And Text

Nov 29, 2009

I would like to format a row of cells. I want each cell in the row to contain (and show) both an interger and text. The interger will range in value from one to ~10,000. The text will always be two characters long...but these characters will change from cell to cell.

Elsewhere in the spreadsheet I will have a cell (w/ a formula) that counts the values of the intergers in the row, but ignores the text in each cell.

a procedure for format ing the cells in the row?

View 9 Replies View Related

Custom Number Format To Show Difference In Two Dates

May 11, 2006

I'm trying to get an excel custom number format to show the difference in two dates as 0 years and 0 months...for e.g.

Cell a1 = commencement date = 1/1/05

cell a2 = expiration date = 12/31/10

Then cell a3 = Lease Term = 6 years 0 months.

View 2 Replies View Related

Show Custom Error Message When No Data To Paste

Aug 27, 2007

Below is a macro I recorded to help copy 'Paste Special - values only' data between two spreadsheets that have different colour and conditional formatting in cells.

However, if this is run and there is no data to paste, it throws up the End and Debug error.

Any chance that someone knows that if there is no data sitting on the Clipboard, then a msg box would appear saying "Please select the data you require to be copied" in the message box.

Sub data_input()

ActiveSheet. Unprotect
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("B5:AG4804").Select
Selection.sort Key1:=Range("B5"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
Range("B5").Select
ActiveSheet.Protect

End Sub

View 4 Replies View Related

Show UserForm Before Printing For Custom View Choice

Apr 9, 2008

When I click the excel printing icon, I want a userform to pop up in which I make the choice for a certain customview that I build. This customview must then be printout. Note that I want to use the standard Excel print icon, not a custommade one in the worksheet. I figured out some code, but it doesn't work. For instance my if structure returns "false" even if I did click that commandbutton, see the code below.

Private Sub Workbook_BeforePrint(Cancel As Boolean)
Static PrintRequest As Boolean
formMyview.Show
If formMyview.CmdCancel= True Then
MsgBox "printrequest canceled"
Unload Me
cancel=True
Exit Sub
End If
If PrintRequest = True Then
Exit Sub
End If
If formMyview.CmdOk = True Then
For Each Myoption In frameViewoptions.Controls
If Myoption.Value = True Then..........................

View 6 Replies View Related

Show/Hide Specific Columns For Custom Views

Jun 12, 2008

I have a spreadsheet with four columns of data for every month (i.e. January has a Prior Year, Budget, Outlook, and Actual column). I have been trying to come up with a macro or form that will allow me to customize which columns I would like to see and hide the rest. For example, if I chose to see the Budget and Actual columns, it would hide the Prior Year and Outlook columns for each month.

View 2 Replies View Related

Custom Formatting - Show Numbers On Excel Spreadsheet In Thousands

Jun 14, 2013

I want to show numbers on my excel spreadhseet in thousands. However, the challenge is I want to show negtive numbers in red within brackets. For instance, I have a number -104,784,089. I want to display it as (104,784) in red color. Similarly, I want to show 577,090 as 577. Is there a customer formatting I can set up in excel that do that?

View 2 Replies View Related

Using Variables In Macro Functions?

Jun 27, 2014

My goal is to write an equation that allows me to total all of the numbers in a column until the value = 0.

When I write the following equation using actual cell references, I am able to get the results I am looking for:

=IF(LEFT($E$78,6)=" Expe",SUM($J$78:INDEX($J$78:J1000,MATCH(0,J78:J1000,),0)),0)

When I try to write it in a macro using variables, I get all messed up:

Selection.Offset(1, 0).Select
Selection.Font.Italic = True
ActiveCell.FormulaR1C1 = " Expense"

[Code].....

(Possibly unnecessary information: This is for a budget spreadsheet I am creating. Ideally when I am finished with the macro it will allow me to add a line item under a specific program and update the total amount spent. The budget is broken out by month, rather than program. When a new program begins the amount in column J will always be zero, hence the Sum until 0 is reached.)

View 1 Replies View Related

Index And Match Functions In Macro Code

May 26, 2008

I want to write the following function using VBA. =index(B2:D8, match(lookup_value, A2:A8, 0), match(lookup_value, B1:D1, 0))

View 8 Replies View Related

Insert Row Macro To Copy Down Conditional Format & Functions

Jul 6, 2009

I have a spreadsheet whereby in each cell of a row there may be a formula or/& conditional statement applicable. I would like to create a macro that can perform the insert of the new row as well copy down from cell above applicable functions as well as conditional formats that maybe resident. Can this be done?

View 8 Replies View Related

Extracting Numbers From Text Using Macro Or Excel Functions

Dec 10, 2012

I am trying to extract values from a text. I used macro to solve the problem. I was able to extract the numbers however i am trying not to extract all of the numbers in text. For example as you can see below, i am trying to get only 22.99 The only unique thing here can be $ sign i believe. I need to put a criteria that selects the number right after $ sign and extracts 5-6 decimals after that.

**work lamp/desk light led;orion8879 final price: $22.99 (store)**
this is the text in a cell and i only need 22.99 not 8879)

View 9 Replies View Related

Custom Function To Run A Macro

Aug 11, 2004

I am wanting to create a custom function that i can enter into a cell to run a macro (MyMacro). I do not know how to write a function, but so far i have:

Public Function Run(MacroName As String)
Application.Run MyMacro
End Function

View 6 Replies View Related

Macro- Custom Filter Containing

Jun 8, 2009

I'm trying to write a macro that will custom filter a column for cells containing the value in a cell, the macro I have so far is:

Sub Filter()
ActiveSheet.AutoFilterMode = off
LookupVal = Range("C3")
Range("A8").AutoFilter Field:=4, Criterial:=LookupVal
End Sub

However that only returns cells that are equal to C3, normally to do contains I would put "* *" around the value but then that removes the reference to cell C3.

View 2 Replies View Related

Add Custom Macro Buttons?

Mar 6, 2012

adding custom 16 x 16 buttons to toolbars, which weren't preset images or using the built in deisgner.

Was hoping there may be an add-in giving more variety of buttons or a way to import set images. Very frustrating as there are many microsoft 16x16 bmps / icons that would be ideal but the choice is extremely limited.

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved