Trim Trailing CR / LF Character(s) Off Of String Variable
Jan 31, 2014
I've spent way too much time trying to figure out this simple thing. Doh! I have a text string that may have one or more CR and/or LF characters on the right. Unfortunately, RTrim doesn't remove CR/LF characters.
Is there an easy way to do something similar to the following that will remove the CR/LF characters?
I have come up with this to Trim all of the data from rows 2:30 removing any trailing spaces after the last word in each cell. The macro takes a couple of minutes to run have I got something wrong that is making it run slowly or does the Trim process just take longer?
Sub TRIM_RANGE() Dim myRange As Range Dim myRow As Range Sheets("CAMPAIGNS_2007").Select Set myRange = Range("2:30") If myRange Is Nothing Then Exit Sub Application. ScreenUpdating = False myRange.Replace What:=Chr(160), Replacement:=Chr(32), _ LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False For Each myRow In myRange.Columns If Application. CountA(myRow) > 0 Then myRow.TextToColumns Destination:=myRow(1), _ DataType:=xlFixedWidth, FieldInfo:=Array(0, 1) End If Next myRow Application.ScreenUpdating = True End Sub
to trim leading and trailing spaces from values I'm getting from a For Next routine. I'm using c as my variable and Trim(c.value) as the operation.
There are other routines that search for the explicit string that's the result of the trimmed value and some can't be found because the trim as I'm using it isn't trimming.
Is there a fomula that can add trailing spaces. For example....I need a certain feild to be 11 Characters in length. So lets say in Column A, I have a bunch of different words:
House Bird Up Down Yes No
I would like to put a formula in column B that takes my original text and adds blank spaces to the end of it until it's 11 Characters. So "House" in Column A would be "House " in column B.
I need your guys expertise in the following formula. I'm applying the following to a large range of data that varies in lenght,however all of the data has a 1Y or 2Y at the end of it. I need to remove it from the data into a new column. Currently I'm using =trim(mid(A2,1,30) how can I change my formula to obtain my results?
I have a problem that I just dont seem to have the brain power to solve right now. I have a list of websites and I need to extract all characters after the last / in the URL. URL example:.....
I have been using the find function in conjunction with LEN and RIGHT etc but the multiple instances of / is causing headaches for me. Also, the trailing string of characters that I want to extract can be both text or numeric and are of differing lenths.
I am trying to develope a "goto" page macro where the page value maybe 1,34,7A, 256C etc. I am not clear on how an inputbox value can be compared to a string variable or a numeric variable at the same time. This is what I have done, but when the texboxvalue is "7A" it doesn't work.
I'm looking for some VBA code that would look at a column of data, look at each cell value in that column and if the cell value starts with the letter 'G' and the 5th character in that cell is not 'Z' or 'X' I would like to highlight that cell. Example:G123-123 would be highlighted whereas G123Z-123 would not.
I would like to get the nth character from a string. For example, let's say there is a string "jupiter", and I would like to get the 3rd character of this string, "p". Is there a function in excel vba that would allow me to do this?
Say you define a public range variable called Inputworksheet and you set it to refer to the worksheet called Inputworksheet. You have a separate string variable with the value Inputworksheet. How do you get this string variable value to call/control the range variable Inputworksheet?
I am getting an excel worksheet value from a lookup function that corresponds to the name of a VBA range variable. Once I have this worksheet value, I would like to use the range variable that has the same name as the worksheet value.
I have this data and want to extract the character after the letter Y if the string has a Y in it.
Example data Output
AU 2013 OD ANR B24 Y2 2 AU 2013 OD ANR B24 Y4 4 AU 2013 OD ANR B24 Y5 5 AU 2013 PD HLD NOV B SPA AU 2013 PD HLD NOV C SPA AU2013OD ANR B25 Y1 1 AU2013OD ANU B25 Y5 5 AU2013OD WCR FPVN B49 AU2013OD Y6 FPVN B49 6 AU2013OD WCR FPVN B40 AU2013OD WCR FPVN B43
I have a web query that returns a city and state, but the last character of the state is lower case. I need VBA code to change the last char to upper case. Here is what I have so far:
I have a column that has various codes such as "E123" and "X456" and "S345". I just want to extract the numbers and leave the letters in each cell. How do you write a formula using the LEFT function to extract the last three numbers?
I have a cell that has approx 22000 characters. I'm trying to remove a specific character string from a cell by doing a find and replace with "". It works for characters in the first part of the cell but not for characters in the last part of the cell.
Example: I do a find/replace for the characters 21242 to "" in column A and I get the expected results. I do a find/replace on 69294 to "", again I get the expected results, but if I do a find/replace on 85203 to "", I get "Excel cannot find what I am searching for" (but its there!)
My cell size is within the max size of 32,767 characters so not sure why its not working.
I would like to find the position of the last occurrence of a character in a string. For example, I have a string with the following:
"c:wwgpeToolbidsTest File.GP$".
I would like to find out the position of the last '' in the string because I want to pull the filename, 'Test File.GP$' into a variable. I would like to avoid writing code to do this. Are there some Excel functions I can use for this?
I have a macro that asks the user to enter a file name and have written a small function to search the name given to the file to find any invalid characters, trouble is I must be doing something wrong as I doesn't work. Everytime I write something in the box I'm told it's invalid, regardless of weather it actually is or not.
I am trying to work out how to get nth position of a character in a string. For example in this
Code:
kjishdfiuayigdscka if I use the formula Code: =FIND("i",I$1),
it will give me answer 3. But I want the position of 3rd "i" in the string. The answer should be 12. How can I change this formula to get the correct result?
The barcode lablels all have the following format: A318639....that is a letter followed by six numbers.
When I scan the barcodes into any cell, a dollar sign "$" appears in the front of the barcode string that is entered into the cell. The dollar sign is not a relevant part of the string of characters in the barcode label.
What I am looking for is a solution where upon scanning a barcode into any cell, the dollar sign is removed from the front of my string and I am left with just the seven character string which is shown above.
I have experimented with the Data Validation tool by trying to limit the number of characters that are allowed in a cell to seven characters, but that has not actually removed any characters from my data string.
I am trying to remove the last 6 character from a variable. I worked out how to do it using formula's in XL, but want to move this in to VBA. Currently I have this