I have a chat log someone pasted in MS Word and gave to me, but in pasting all the carriage returns between chats were stripped off. Each chat starts with a date in 'MM/DD/YY' format (month can be 1 character only).
I only have access to VBA and I need to insert a new line before each occurrence of a date in order to render this document more human-readable.
You can do this without VBA, using find and replace. Ensure "use wildcards" is selected.
Find: ([0-9/]{7,8}). This matches 7 or 8 occurrences of a single digit or forward slash. The () captures the text for use in the replacement.
Replace with: ^l\1. This replaces with a line break character followed by the captured text.
If there's numeric data other than dates, you might need to be a bit more specific with your find string: ([0-9]{1,2}/[0-9]{2}/[0-9]{2}).
Related
I have a problem with an .CSV file.
Some of the values are prices with a comma to separate units and decimals, all the other fields are separated with a comma too.
So, as expected, it is impossible to convert my csv file like this. (If there is a way, please tell me)
Therefore, I am trying to write a vba macro that will replace the comma by a dot.
More specifically, I need to replace the 9th occurence of "," to a "." IF AND ONLY IF the character next to the comma respects a specific condition. That is why I need a macro to do so.
In excel, I was using the following formula to find the position of my comma:
=Find(char(160),substitute(A2;",";char(160),9))
This formula gives me the position of the 9th comma, that's perfect. I would like to know how to code this in VBA
Thanks in advance !
Alex
I need to be able to find every place in my document (hundreds of pages) where there is a formatting change without a space. For example:
a bold partnext to regular text
Or red text next to black with no space. I want to have my macro find each "word" (in the vba sense) like this, and execute code based on that character location accordingly. (The loop should identify the character position where the format change occurs... although I can do that part with a loop through the characters within the found word).
Is there a simpler way to do this than by looping character by character through the whole document and checking for a difference in formatting, which would be too resource-intensive?
Thanks for your help.
I am working on a macro that needs to be able to check and make sure that a character on a certain line is what it should be before it finishes the form.
Where or how do i find the information to do this?
I have tried using the command "Left(#of line ,1)" and am not getting it to return anything at this point.
I Assume that you have this text in a string. Comment to my answer if wrong.
You can use a Regex to compare to string with your character like so :
If Regex.IsMatch(MyString, *.{X}Y) Then
'You have to manually replace X for the number of characters before the character you scan for
'You have to manually replace Y for the-said character it is supposed to be
Look at http://www.codeproject.com/Articles/9099/The-Minute-Regex-Tutorial for more info on Regex.
If you want to only take one line in your string :
TheLine = split(MyString,Environnement.Newline)([Line Number])
I want to create a makro in Excel which performs - after pressing a button - the below. I attached some dummy data that is formatted like the actual sheet.
There are several data blocks that are seperated by headlines in Sheet 1. From these headlines, I want to get a string of numbers and put it into column S for each line with data below that heading. In line 6 the heading says "2000", thus lines 8-19 should have a "2000" in column S and so on. The number I want to get is always after the word "Monthlyaccount" but the lenght of the number can be different - from 1 to 7 digits.
For lines where no data is given (data lines might be recognized by looking if in A is a valid date given) there should just be "ERR" instead of the number.
Can anyone help out?
Thanks so much upfront!
Say the string (in cell A1) contains "Monthlyaccount" followed by a blank followed by a number followed by another blank. To extract the number, use:
=--LEFT(MID(A1,FIND("Monthlyaccount",A1)+15,9999),-1+FIND(" ",MID(A1,FIND("Monthlyaccount",A1)+15,9999)))
This does as requested. Paste the following into S3 and drag down
=IF(AND(ISNUMBER(RIGHT(A2,4)*1),ISNUMBER(RIGHT(A3,4)*1)),S2,IF(ISNUMBER(RIGHT(A3,4)*1),LEFT(RIGHT(A1,LEN(A1)-FIND("Monthlyaccount",A1)-14),FIND(" ",RIGHT(A1,LEN(A1)-FIND("Monthlyaccount",A1)-14))),"ERR"))
This happens every time I paste a line of code containing a string into Xcode. for example when I pasted this into Xcode:
simonLabel.text = #"Good Job!";
I received an error saying that there was an "unexpeceted '#' in program"
If I delete everything and retype exactly the way I pasted it I do not get an error.
There are too many problems that can appear there:
" can be a different character that you expect
(space) can be a different character that you expect
invisible characters. Something you won't see in the editor at all but they got there with the copy-paste.
All these problems can happen because
You copy it from a website with different encoding (or from a really badly writter website)
You copy it from a smart editor (e.g. MS Word, Open Office) which replaces some of the characters to match locale (e.g. quotation marks) or replaces/add spaces based on grammar and word wrapping (e.g non-breaking space).