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
Related
I need help translating a common Excel function, into VBA code.
Please see attached screenshot for the code I already have started.
I am using the calculations seen in the screenshot to build a scorecard/grading worksheet. I will need to adjust the rows in each of these, but never the columns.
Once I figure this out, I will then loop these to repeat for each new row as they are added.
image of my code, so far
When a literal string needs to contain double-quote characters, you need to use two double-quotes in a row for each double-quote you need in the string.
So your string
Range("AP4").Formula = "SUM(COUNTIFS(J3:AR3,{"0","1"}))"
needs to look like this:
Range("AP4").Formula = "SUM(COUNTIFS(J3:AR3,{"“0"”,""1""}))"
You can also do this without putting the formula into the content of the cell like this:
Range("AP4") = WorksheetFunction.SUM(WorksheetFunction.COUNTIFS(J3:AR3,{""0"",""1""}))
I have a spreadsheet that I have imported from one of our sites that we use for User Access. I am having trouble in the formatting of the spreadsheet in order to make it searchable and to use VLOOKUP. In the Full Name column, the first and last name look like they are separated by a space " " but it does not work that way when I try to split them into First Name and Last Name columns. It is almost like it is a fake space. I have tried many ways to make it a true space between the words but nothing has worked and none of my researching to find a solution to this problem has been found. Can anyone help me with figuring this out so I don't have to continue to delete the "fake space" and add a real space between the words?
Any help is much appreciated.
These are non-breaking spaces. I am guessing that this data is coming from an HTML source.
You can get your formulas to work by changing " " to CHAR(160), which will return the non-breaking space (ASCII code 160).
In excel 2007, I would like to apply a formatting rule throughout my entire workbook, which will format a row if and only if that row contains one or more cells with a question mark. I'm trying this formula:
=IF(countif(c2:l2, "?")>0)
Where row 1 contains a header, and the values that I would like to check should range from columns C to L. Excel says that there is an error however, can anyone see what that error is?
The problem is that "?" is a wildcard. You need to escape it with a tilde:
=COUNTIF($C2:$L2, "~?")>0
Also, you didn't have absolute referencing for the columns. Also, you don't need IF in a conditional format. The "condition" is the IF.
I have to read the text from the cells of a column in excel and search for it in another sheet.
say for example, the text in sheet1 column A is "Evoked Potential Amplitude N2 - P2." This has to be searched in sheet2 column C. This fails because a question mark appears before the "E" which is not present in the value in the sheet2.
Both are representation of same character in different application. Maybe someone might recognize it.
In the excel sheet I don't see any junk characters, but while handling it in the vb code I see a question mark before the word - Evoke.
This data was extracted from a share point application and this character (?) is not visible to the plain eye. Search and replace functions are not working in this case.
Unicode 8203 is a zero-width space. I'm not sure where it's coming from. It is probably a flaw in the way the data is imported into Excel which you haven't noticed before, but it might be worth fixing.
In the meantime, you can simply use the Mid() function in Excel VBA to remove the unwanted character. For example instead of
x = cells(1,1).value
use
x = Mid(cells(1,1).value,2)
which deletes the first character.
I'm trying to use VBA to write a formula into a cell in Excel.
My problem is that when I use a semicolon (;) in my formula, I get an error:
Run-time error 1004
My macro is the following :
Sub Jours_ouvres()
Dim Feuille_Document As String
Feuille_Document = "DOCUMENT"
Application.Worksheets(Feuille_Document).Range("F2").Formula = "=SUM(D2;E2)"
End Sub
You can try using FormulaLocal property instead of Formula. Then the semicolon should work.
The correct character to use in this case is a full colon (:), not a semicolon (;).
The correct character (comma or colon) depends on the purpose.
Comma (,) will sum only the two cells in question.
Colon (:) will sum all the cells within the range with corners defined by those two cells.
Treb, Matthieu's problem was caused by using Excel in a non-English language. In many language versions ";" is the correct separator. Even functions are translated (SUM can be SOMMA, SUMME or whatever depending on what language you work in). Excel will generally understand these differences and if a French-created workbook is opened by a Brazilian they will normally not have any problem.
But VBA speaks only US English so for those of us working in one (or more) foreign langauges, this can be a headache.
You and CharlesB both gave answers that would have been OK for a US user but Mikko understod the REAL problem and gave the correct answer (which was also the correct one for me too - I'm a Brit working in Italy for a German-speaking company).
I don't know why, but if you use
(...)Formula = "=SUM(D2,E2)"
(',' instead of ';'), it works.
If you step through your sub in the VB script editor (F8), you can add Range("F2").Formula to the watch window and see what the formular looks like from a VB point of view. It seems that the formular shown in Excel itself is sometimes different from the formular that VB sees...