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 .
I'm currently trying to compare all of my companies data sources for staff, ie helpdesk, telephony, ldap etc. and I have made quite a bit of progress, mostly thanks to this forum, however one issue I am running into, is the fact that when I use the text to columns funtion (in a macro) it's splitting up names which are double barrelled into 3 columns. The names are in the format of...
I've got a userform for pricing items and am having an issue when changing margin. I want to validate the user enters in .22 or 22%. The code places the decimal value in a worksheet just fine and runs back end calculations. I want to make sure no one fat-fingers .12b by accident so I came up with the following code. It seems to run fine, but if I tab over a couple of textbox (there are 4 Margin textboxes) it trips the coding for that textbox even if there was no change to the value.
Code: Private Sub txtPDLaborMargin_AfterUpdate() If IsNumeric(txtPDLaborMargin.Text) Then Range("LaborMargin") = txtPDLaborMargin
What I am doing is setting up a product ratecard sheet to run with our CRM system in work.
Each product has 10 quantities, with 10 different prices, but each product must have the same product code running down in column A
I have thousands of products to put in to dont want to manually type each code in.
I am ok with Excel, but I can not program in VBA, so i am looking for a formula to use.
The code is ZTRA-00001, which will stay the same for 10 rows, then there will be a space of 1 row and the next code for the next 10 rows in the column would be ZTRA-00002 etc.
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've developed a little software using Excel Macros & VB. To prevent people from accesing the code I protected the code blocking it from visualization. It seems not enough as an acquaintance of a friend cracked it in 25 minutes. Or so he says. So I'd like to know if there is a better way to protect the font code.
I have an excel file having part code,name,vendor and Qty ( Quantity ).
My problem is that I want to apply an excel formula to pick up that vendor code who have highest Qty of a part code.The condition is that S.No.should not be disturbed.This file is so large,but here I have taken an example,
I have an export from a database that I'm bringing into Excel 2010 of about 30K records. Data points are recorded numerically and I have their associated text "value label" (what it would be called in STATA, for example, not sure what it's called in Excel). I want to create various charts/pivot tables with the data and want the labels to be the text label, not the number.
For example, variable ASSIGNMENT has the following possibilities:
1 2 3 4
Here's what each of those "mean" (I have this in another table):
1 - Sick 2 - Overtime 3 - Court 4 - Present
How do I create a chart or pivot table where the labels are "sick", "overtime", etc., and not "1", "2", "3", "4"?
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.
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".
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.
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
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
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.
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.
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
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)
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
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...........................
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
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.
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.??
I have found the code below that is very good and changes the case size to Upper, Proper or Lower. The problem is that when I select a cell, range of cells, column or row it changes the entire sheet instead of the selected range.
Code: Sub CaseSize() Dim myCase, rng As Range, r As Range myCase = Application.InputBox("Enter" & vbLf & "1 for Upper Case" & vbLf & _ "2 for Lower Case" & vbLf & "3 for Proper Case", Type:=1) If (myCase = False) + (Not myCase Like "[1-3]") Then Exit Sub On Error Resume Next
I have a macro that runs through a list and stores elements to an array. If the element is not found in my list, it adds to the next available row and adds the value from the array to that cell. Right now, I am searching in column d but am storing the value of column a at that location. When I switch the reference to column D, the value is not inserted into my new list.
Here is my current code:
Code: Sub Arraytest() Dim arr As Variant, lastrow As Long, i As Long, f As Long, l As Long, lastrow2 As Long, insertrow As Long
[Code].....
Why does the code not work properly when I switch to D? The value is storing correctly in the array. I test this by the last line of the code and it executes properly.
Please check this sample file. Say for example; I am sending this file via mail to different agencies. See in this file sheet named base & column title Agency , filters concerned agency wise and send via outlook to the concerned agencies mail id from mailinfo sheet. What my concern is since these are different agencies, I wanted to bring the agency name in the mail subject.
I have a macro called pull that contains a year several times -see sample code below
I woulsd like a macro that will prompt and enable me to change the year from say 2013 to 2014 on the Macro called "Pull" . I intend to set up button to link to the macro
With Workbooks("Fruit & Veg Dept Commisions.2013.per Budget.xls") With .Worksheets("Service") Set cfind = .Cells.Find(what:=CDate(mmonth), lookat:=xlWhole) .Cells(9, cfind.Column) = x
This Code is Pasting "A1" into the destination - format and all. I need it to only paste in the value.
Sub test() Dim lastrow As Long lastrow = Sheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row Sheets("Sheet2").Range("A1").Copy Destination:=Sheets("Sheet1").Range("A" & lastrow) Application.CutCopyMode = False End Sub
how would one change the actual code words - instead of using if statements i would like to have when statements that do exactly the same thing, i just want to write "when blah then blah"