Change Code From Function To Sub

Apr 20, 2009

I am trying to do is look at the first two digits of the number in column c (Range c5:c5000) if the number starts with 01 then I need the formula in column g = f5*12 if the number is 03 then I want the formula to be g=f5*24 I have several of these "cases" or "if" to put in can someone get me going a little further

Here is what someone gave me to work with but I'm having troubles getting it to work...I get a name error in the cell and I cant use this they way it is because the code needs to go into the sheet mod with a bunch of other code.Also when I use the Option Explicit the rest of my code wont work.

Option Explicit
Function re(Cl As Range, Src As Range)
Dim i As Long
Select Case Left(Cl, 2)
Case "01": i = 12
Case "03": i = 24
End Select
re = Src * i
End Function

=re(C5,F5)

View 9 Replies


ADVERTISEMENT

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:

Code:
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)"

[code].....

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

Change Text Code To Numeric Code?

Apr 3, 2014

I have problem to change text code into numerical code using macro. i have data contain text code and i would like to convert it into numeric . each text code has dedicated numerical code for example I have 4 fluids with text code text code:

FW = Fresh water
SW = Saline eater
CW = connate water
MW = Meteoric water

numeric code as follow

FW=1
SW=2
CW=3
MW=4

I would like to convert the text code into numeric code, it is easy if using excell , but it is routine job for me , i need to create macro to be more simple .

View 1 Replies View Related

Change To Code For Change In Range

Mar 27, 2012

I have recorded the code below that does what I need, problem is I will use the code on files with various amounts of rows. What can I change in it so it will work on all different size files.

Code:
Sub Macro3()
'
' Macro3 Macro

[Code]....

View 6 Replies View Related

If Function: Change In Date

May 30, 2008

i have date values in say, cells a1 to a4

20080522 21:00:00
20080523 14:45:00
20080523 15:00:00
20080523 15:15:00

i would like cell b to tell me when there is a change of date (not change of time), ie insert a 1 in lets say cell b2. i know it will be a simple if function but i dont know how to only read the first 8 digits

View 9 Replies View Related

Change Macro Using InStr Function

Aug 30, 2012

I want to change my existing macro using InStr function in such a way that when the columns are found then it add the corresponding values. The addition of values have already been done. I just want that if similar values are found then it show the results.

The example workbook with macro is attached : comparestrings.xls

View 1 Replies View Related

Change Return Value Of Inbuilt Function?

Oct 18, 2013

The function Hlookup returns #N/A(?) if the value I'm looking for is not found. Is it possible to change this return-value. For exampel to #No or #No value ? I suppose I then need the code of this function? And I cannot get it?

View 1 Replies View Related

Using IF Function To Change Font Color

May 9, 2009

I'm trying to use Excel to keep team standings for a baseball board game. I had no problem calculating wining percentage. Finally figured out how to calculate 'games behind.' Now I'm wondering if there is a way to change the font color of a team name based on their wining pct?

A typical row contains: A2(Team Name), B2 (Wins), C2 (Losses), D2 (Pct (B2/(B2+C2)), E2 (GB). Is there a way to use the IF function to return the 'Team Name' in green if D2>.500, 'Team Name' in red if D2<.500, and 'Team Name' in black if D2=.500 ??

View 4 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

[Code]....

View 1 Replies View Related

VBA - Function To Insert New Row When Cell Value Change

Apr 29, 2014

Input:

A
B
CA001
CA001
CA001
CA002

[Code]...

Output:

A
B
CA001
CA001
CA001
CA001

[Code]...

1. Insert a row whenever cell value change.
2. Insert cell value (in previous column) in inserted row.

View 3 Replies View Related

Function To Returns Biggest Change (+ Or -)

Feb 1, 2010

I have some survey data for 2008 & 2009. I have a column calculating the difference on each question between the two years. I need to show the 20 biggest changes, positive or negative. Which function can I use for this?

View 9 Replies View Related

Dynamically Change The End Value Of A Range In A Function

Jul 20, 2006

I am using the STDEV function on a range of values: STDEV($I$26:I2545). My starting cell is constant and I would like to make my ending cell variable based on a value I enter in a master cell (A1). The value I enter in the master cell is multiplied by 252 the product would equal the row number I would like to stop at. So if I enter 1 the formula will be STDEV($I$26:I252). I tried: STDEV($I$26"I"&(A1*252))) and other such variations to no avail

View 5 Replies View Related

Function Recalculation With Change In Cell

Mar 28, 2007

I have just written a function that sums all the values in the cells in a range that are not green. This works however if one of the non green cells is changed to green the function does not work. i have to re input it into the cell that i put it into.

Function SumNotGreen(SelectedCells As Range)
' Adds the values of the cells where the font colour is not green(35).
Dim Cell As Object
Dim x As Double
x = 0
For Each Cell In SelectedCells
If Cell.Interior.ColorIndex <> 35 Then
x = x + Cell.Value
End If
Next Cell
SumNotGreen = x
End Function

How can i make the function recalculate i.e. go back into the loop every time a change is made.

View 4 Replies View Related

Automatic Change In Code

Jun 16, 2007

Is there any way, in which i can make my code dynamic?? For example, in a code written in VBA, there is a reference to particular sheet, say "ABC". If i change the name from "ABC" to "ABCD" from excel, the underlying code should change automatically from "ABC" to "ABCD".

I want to make my code dynamic..

View 10 Replies View Related

VBA Code That Consider Variable Change

May 25, 2011

Trying to create a VBA code that will enter a formula such as: SUM(Q2:Qt) in a range of cells for instance A2:A10, and if there is information in B11, B12, B13 etc., it will consider that variable change and enter the SUM formula in cells A11, A12, A13.

I read that Dim LR As Long is the solution but not sure how to apply.

View 9 Replies View Related

Change Code To Look Through A Range

Jun 5, 2013

This code is coulnm specific, can this code be adapted to look through a range for a match i write this code up to 25 time changing the column it looks at each time, the row always stays the same the location it paste to also always stays the same if it could be made to look through a range in reducing the amount of code to write.

the range it needs to look through would be, row 6 from column B to column Z.

the line i am hoping to adjust for this is below it reads: "WST.Cells(6, 2)Then"

HTML Code:
If WS1.Cells(8, 2) = WST.Cells(6, 2) Then
WST.Cells(7, 2).Resize(30, 1).Copy
Worksheets("torr1").Cells(9, 5).PasteSpecial Paste:=xlPasteValues
nextrow = nextrow + 1
End If

View 8 Replies View Related

Change The Code To Automatically

Feb 23, 2007

Is there a way that I can add a statement or change my code to automatically have the checkbox checked if a certain value in a cell is greater than zero?

This is my
If CheckBox1.Value = True Then Range("RANGE_WATER_AND_SEWER").PrintOut Copies:=1

If CheckBox2.Value = True Then Range("RANGE_ELECTRICAL_SERVICE").PrintOut Copies:=1

etc. Note: I have about 80 checkboxes on my form.

View 9 Replies View Related

VB Code To Change DIR Drive

Oct 24, 2007

I have part of the code below and need to modify it so that others who only have C: instead of D: to use it

Filename = "D:TempBudgetMonthly.xls"

FileExists = (Dir(Filename) "")
If FileExists = False Then
msg = "The data file Monthly.xls does not exist !! Load the required file and run the report again !"

If MsgBox(msg, vbExclamation + vbOKCancel) = vbOK Then
End If
Exit Sub
End If

I need code to replace all D: to C: for the entire PROJECT not MODULE.

View 9 Replies View Related

Change VBA Code In 100+ Workbooks

Apr 23, 2008

I know that there has got to be a post on here somewhere on this, but anytime I enter in "Import VBA Code" I get back loads of stuff that really isn't relevant.

In post [url] I had to change a line of code so that the formatting macros I made would be accessable to everyone.

Now that I have the fix in place I must import the fix in the one line of code into 100+ workbooks. I suppose I could do this manually, but I imagine that there is a much faster way to do this using VBA.

I was flipping through the "VBA and Macros for Excel" book by Mr. Excel and on page 334-335 I came across something that looked like it might work. However, it seems that this code is switching modules and my code is pasted in "ThisWorkbook".

All of the files are located in the same directory, so it would involve opening all the files in the specified directory, making the VBA code change, saving the file and closing.

View 9 Replies View Related

Change Code To Find Last Row

Feb 25, 2009

I have a workbook with several sheets that get info from sheet"Main BOM". I use a =Main BOM(a6) type formula on the top row of other sheets where info is needed and I drag that down to the end of info on the Main BOM to get the info into other shhets of the workbook.
How would I alter this code to find the last row of data on the Main BOM tab and only drag down that far? Or would I need a completly user written macro? This is a recorded macro.

Sub DragDown()
'
' DragDown Macro
' Macro recorded 2/25/2009 by David D
'
Sheets("David,Jimmy--To Proto").Select
Range("A16:E16").Select
Selection.AutoFill Destination:=Range("A16:E47"), Type:=xlFillDefault
Range("A16:E47").Select
End Sub

View 9 Replies View Related

Change Format Code

May 26, 2006

Can Attached code be changed to alter font colour,type. rather than just fill colour.

Private Sub Worksheet_Change(ByVal Target As Range)

Dim icolor As Integer
If Not Intersect(Target, Range("e:Az")) Is Nothing Then
Select Case Target
Case "Ph"
icolor = 6
Case "Li"
icolor = 12
Case "O"
icolor = 7
Case "An"
icolor = 53

View 3 Replies View Related

Change Code To Activeworkbook

Jul 4, 2007

This piece of code successfully replaces a module in a range of workbooks -

Sub CopyOneModule01()
Const strModName As String = "Module1"
Dim FName As String
Dim vWbkNames As Variant
Dim lLoop As Long
vWbkNames = Array("CFADS01", "CFADS02", "CFADS03", "CFADS04")
With Workbooks("CF266") 'copies from here
FName = .Path & "code.txt"
.VBProject.VBComponents(strModName).Export FName
End With...........................

View 2 Replies View Related

Run Code On Cell Change

Jun 18, 2008

I am currently making a spreadsheet that will calculate the costs of products that my company makes. I have created the code that will add a line for each component of the product and fill in the details, but i want to set it so that it run's when i change the part number field in the sheet.

The only way i know to do this is using the worksheet_change event, but i will have more than one of these 'calculators' on one worksheet and the part number field will not always be the same cell.

I thought that an IF statement would work, as the cell next to the part number will always be the title "Parent". This is the code that i have tried but i keep getting run time error 1004 application-defined or object-defined error when the IF statement would return TRUE, when the IF statement returns FALSE (the cell to the left is NOT "Parent") the code exits, which is correct.

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Offset(0, -1).Value = "Parent" Then
Code.....
End If

View 3 Replies View Related

VBA Userform Vlookup Function To Change Cell?

Dec 11, 2012

I have a Password login userform on my workbook for users to enter their username and passwords.

Now i want to make a userform where users can change their passwords.

With the login userform i used a application vlookup function to see if the username and password are corresponding. how can i code a userform to look for the username in column A and then change the password in column B?

Password.xlsm

View 9 Replies View Related

Find And Replace Function - Change Text To Pop Out?

Sep 9, 2013

Here is the situation:
- Large block of text in one cell (1000+ words).
- I use the Find & Replace function (from the top menu) to find a specific word that may appear several times within the cell.
- Excel "highlights" the cell... but not the word specifically so I have to read all the text to find that word throughout the cell.

View 5 Replies View Related

Coding On Change Function In Combobox And Text Box?

Jul 5, 2014

How to make it function able. Here are the details.I have a user form named UserForm1 in the user form I have a text box and combo box. Combobox is named as ComboBox1 and text box is named as TextBox1.

Along with the above 2 fields in form, I have 2 labels, Label2 & Label6.

TextBox1 contains date (which user can either type or chose form calendar), and ComboBox1 will have Employee ID that needs to be choose. Upon selecting both, my Label2 caption should have employee name & Label6 caption should have shift time.

By using formulas in excel I have employee name in Sheet2 cell b2 and shift time in Sheet2 cell b3. Upon change either in ComboBox1 or TextBox1, I want data in Sheet2 cell b2 be the caption of Labe2 and data in Sheet2 cell b3 be the caption of Labe6.

What is the code to get this done, if either of them is blank, then label caption should be blank.

View 2 Replies View Related

IF Function To Change The Colour Of The Text In A Cell

Dec 14, 2008

how I format the IF function to change the colour of the text in a cell, I know how to use conditional formating but it wont do what I need it to.

The formula I'm using (See Below) only inserts the word "Red" or "Green" in the cell it does not change the colour of the text.

=IF(H6=A1,"green",))

View 9 Replies View Related

Dsiable Code On File Name Change

Mar 12, 2009

I have an Excel workbook which operates as a template. When it is opened, it runs an OnOpen routine. When it is saved under a different name, is it possible to ignore the OnOpen routine if that file is re-opened? I suspect it could be done by testing the name of the file, but I can't figure out the code.

View 2 Replies View Related

Label Caption Change... Run Code

Sep 30, 2009

I have just noticed that there is no defult event for the running code after updating a label caption. I would like to have like a textbox does (Change,AfterUpdate). to run code on the label caption change. could it be done with activex?? can it be done at all.??

View 2 Replies View Related







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