I am trying to create a VBA script that contain a certain text in French, it actually works well on my MacBook with the Lucida Grande font but since this font doesn't exist on windows the macro does not work in it and whenever I change the font to any one that could support French language it neither delete the characters or replace them with insignificant ones, a part of the code is below, please if some one have the answer i will be so grateful. thank you.
For i = 2 To LRow
' colonne E "."
index = WorksheetFunction.Match(".", Sheets("DATA_1").Range("1:1"), 0)
If Cells(i + 1, index).Value = "" Then
Cells(i + 1, index).EntireRow.Delete
End If
'colonne K "Quelle était votre situation professionnelle 6 mois après l'obtention de votre titre (mois de février) ? "
index = WorksheetFunction.Match("Quelle était votre situation professionnelle 6 mois après l'obtention de votre titre (mois de février) ?", Sheets("DATA_1").Range("1:1"), 0)
If Cells(i + 1, index).Value = "" Then
Cells(i + 1, index).EntireRow.Delete
End If
Related
I was working on an excel template to make quotes. This template has a list of materials which you can validate so that a quote is automatically generated.
In itself, the template works fine, the problem appears when I try to add a new function, which will allow you through "UserForm" to insert a new item to the list.
Before this function, I was using the "=CONCATENATE" command to drag several items from the list to the final quote and added a "CHARACTER(10)" so that there is a line spacing between each item because it must appear in unified cells so that then the command "=SHEARCHV" returns all the items. When trying to automate this process, I realize that when I add a new row to the list, it is not added to the list of "=CONCATENATE" so, even though it works in the total sum, the specific item never appears in the description of the items in the final quote.
here some captures
First Step: Check whatever item you want to add
Second Step: The item will move to another sheet to add taxes and prorate as well as labor
Third Step: After that I should send the items that are separated in a single cell and with a space between each one so that finally the function "=SHEARCHV" looks for the "Server Room" and returns me the description of the items like the next image
In the yellow format you can see how the template worked before adding this new function
What I want to do is that when adding a new item to the list I also add a function which can insert several cells in a combined multiple cells, so that there is a line spacing between each item
Main lenguaje: Spanish
Excel Download: https://drive.google.com/file/d/1xUxd7Ze6AB25MVfyxlY9dSlWUeQBTDCH/view?usp=sharing
VBA CODE TO ENTER NEW ITEM
Sheets("PREVISTA").Range("A25").EntireRow.Insert
Sheets("PRORRATEO").Range("A48").EntireRow.Insert
Sheets("HOJA DE DATOS").Range("A22").EntireRow.Insert
Sheets("HOJA DE DATOS").Range("A22") = 1
Sheets("HOJA DE DATOS").Range("C22") = 1
Sheets("HOJA DE DATOS").Range("B22") = TextBox1
Sheets("HOJA DE DATOS").Range("G22") = TextBox2
Sheets("HOJA DE DATOS").Range("E22") = "=G22*'DATOS DE INTERNET'!C2"
Sheets("HOJA DE DATOS").Range("H22") = "=G22*C22"
Sheets("HOJA DE DATOS").Range("I22") = "=G22*$I$2"
Sheets("HOJA DE DATOS").Range("J22") = "=G22*$J$2"
Sheets("HOJA DE DATOS").Range("K22") = "=G22*$K$2"
Sheets("HOJA DE DATOS").Range("L22") = "=(K22+J22+I22)*$L$2"
Sheets("HOJA DE DATOS").Range("M22") = "=(I22+J22+K22+L22)*C22"
Sheets("HOJA DE DATOS").Range("N22") = "=H22+M22"
Sheets("PRORRATEO").Range("C47").Copy: Sheets("PRORRATEO").Range("C48").PasteSpecial xlPasteAll
Sheets("PRORRATEO").Range("V47").Copy: Sheets("PRORRATEO").Range("V48").PasteSpecial xlPasteAll
Sheets("PRORRATEO").Range("X47").Copy: Sheets("PRORRATEO").Range("X48").PasteSpecial xlPasteAll
Sheets("PRORRATEO").Range("F48") = "=C48/$C$2"
Sheets("PRORRATEO").Range("G48") = "=F48*$D$17"
Sheets("PRORRATEO").Range("I48") = "=G48/($C$20+$C$3)"
Sheets("PRORRATEO").Range("J48") = "=I48*$F$9"
Sheets("PRORRATEO").Range("K48") = "=J48+G48"
Sheets("PRORRATEO").Range("O48") = "=N48+M48+L48+K48"
Sheets("PRORRATEO").Range("B48") = "=CONCATENAR(X48)"
If CheckBox1.Value = True Then
Sheets("PRORRATEO").Range("L48") = "=K48*L24"
ElseIf CheckBox2.Value = True Then
Sheets("PRORRATEO").Range("M48") = "=K48*M24"
ElseIf CheckBox3.Value = True Then
Sheets("PRORRATEO").Range("N48") = "=K48*N24"
Else
Sheets("PRORRATEO").Range("N48") = "=K48*N24"
End If
Sheets("PRORRATEO").Range("Q48") = "=O48/O5"
Sheets("PRORRATEO").Range("R48") = "=Q48*O6"
Sheets("PREVISTA").Range("C24").Copy: Sheets("PREVISTA").Range("C25").PasteSpecial xlPasteAll
Sheets("PREVISTA").Range("N24").Copy: Sheets("PREVISTA").Range("N25").PasteSpecial xlPasteAll
Sheets("PREVISTA").Range("P24").Copy: Sheets("PREVISTA").Range("P25").PasteSpecial xlPasteAll
Sheets("PREVISTA").Range("B12") = "=CONCATENAR(P12:P26)"
End If
End Sub ```
I hope I have expressed myself well, any help is welcome thanks
My MATLAB code produces data that I want to send to Excel. I use ActiveX Server in MATLAB to both produce the Excel file and to do the export (I can control more properties of the resulting Excel file this way than by using the 'writetable' command). In the produced Excel file, I manually have to chose the menu 'Data/Filter' to turn on the function letting me filter and sort each column (visible as the small triangles in the column headings as shown in the illustration below).
How can I turn on this function with ActiveX from MATLAB?
Call the AutoFilter method on an Excel Range object. For example, if you have a worksheet object MySheet:
rangeToFilter = get(MySheet,'Range','A1:B3');
rangeToFilter.AutoFilter
You can use a simple function that helps you to get the range depending on the size of the data that you will send to excel. For example:
idx2=size(data,2);
rangeToFilt=join(["A1:",idxtoexcel(idx2),"1"],"");
rangeToFilt.AutoFilter
function rexcel=idxtoexcel(idx)
% Función que permite obtener el número y letra de las filas y columnas que ocupará una matriz a imprimirse en un libro de excel.
alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
if idx < 27
rexcel = alphabet(idx);
else
idx2 = rem(idx,26);
if idx2 == 0
rexcel = [alphabet(floor(idx/26)-1),'Z'];
else
rexcel = [alphabet(floor(idx/26)),alphabet(idx2)];
end
end
Scenario:
I am helping to clean .xls files we are getting from 3rd Parties. They are submitting horrific looking .xls. We are using IBM Datastage(DS) to upload the data but the list below and their special chars are crashing our DS job, these are first names, and last names. Is there a way in Excel to strip the columns from all special characters
Special Chars:
(~*, ",", " “ ", "‘", "~", "?", "Ñ", "Á", "’", "Í", "é")
Currently we are:
ctrl + F to find the special chars and delete them with a space and sometimes the hidden characters we have to remove on the .TXT because they won't show on .xls until they are saved on the .txt.
We have over 85 files to clean and there has to be an easier way to format these files. Please help :(
1) Alt + F11 on excel
2) Insert Tab
3) Module
4) Copy Paste this there and save (you can close the window)
Function Remove(Str As String) As String
'UPDATE BY PITAARA TECH
Dim xChars As String
Dim I As Long
xChars = "=/.',#$%#!()^*&~?-“ ’"
For I = 1 To Len(xChars)
Str = Replace$(Str, Mid$(xChars, I, 1), "")
Next
Remove = Str
End Function
5) Insert a column to the right of the column you wish to remove special chars
6) Enter =remove(column) hit enter
7) Drag down
I need help scraping information from InternetExplorer to an Excel Workbook .
When i scrap, information in the innertext property is correct, but in the excel it comes wrong.
Using the code:
Workbooks("Automatizar PSA").Sheets(1).Cells(linha, 5).Value = ie.Document.getelementsbyclassname("tr-visualizar-detalhes text-center")(i + 1).innertext
I think this is caused because they assume diferent variables, i used variable inspection and got:
Watch : : ie.Document.getelementsbyclassname("tr-visualizar-detalhes text-center")(i + 1).innertext :
"06/04/2017 11:09 " : Variant/String : Módulo11.PSAScrap
Watch : : Workbooks("Automatizar PSA").Sheets(1).Cells(linha, 5).Value :
04/06/2017 11:09:00 : Variant/Date : Módulo11.PSAScrap
Any help, how can i fix that? Sorry for the way i posted, not familiar with forums, how can i paste it as code?
Thank you!!
This is a regional DMY vs. MDY issue. Your sample is DMY/MDY ambiguous so it is impossible to tell what the dates are to begin with or what your system's regional settings are.
The problem with ambiguous dates (where both the month and day-of-month are less than 13) is that Excel will interpret the DMY as MDY or vice-versa. For any others with a day greater then 12, Excel will just put the bad date in as text.
Here is a 'helper' function that will flip DMY to MDY or MDY to DMY.
function flipDMYMDY(str as string)
str = trim(str)
flipDMYMDY = mid(str, 4, 3) & left(str, 3) & right(str, 10)
end function
Use as,
Workbooks("Automatizar PSA").Sheets(1).Cells(linha, 5).Value = _
flipDMYMDY(ie.Document.getelementsbyclassname("tr-visualizar-detalhes text-center")(i + 1).innertext)
Okay I'll try to explain this the best way possible
- I am parsing .txt files which get imported into excel
- The .txt files which are parsed all have static fields (sometimes)
- In the future these fields could change and may not be static therefore the below code would parse pretty sloppy stuff
Questions:
1. Assuming in the future that these string values can change (ie "CUSTOMER NAME:" changes to DISTRIBUTOR NAME:)
a. Is there are way I can manipulate the data to where I only have to establish the name of the strings and skip having to establish the location of the strings within the text based on character length? (ie without using Mid(text, act + 6, 9))
If so, how would I go about doing this? Some lines within the text file have 1, 2 or three fields (ie SOME INDICATOR:,NO STATUS:,AUTO RENEW:.. has three field values, while the first line has one, and the second two. I am guessing one way to do this would be to establish the name of the strings so that every field between said string and the next string would be the string fields value ie:
ACCOUNT OPEN:(string 1) 05/10/15(string 1 value) ACT TYPE:(string 2) PREMIUM (string value 2)
In a nutshell I am trying to find a way that I can making this parser 'intelligent' so to speak. While its no big deal using the below method for the first part of a customers record, in reality each record has additional screens (mainframe). There are also additional screens pertaining to other things such as inventory, order numbers, etc.. So you could see how this could become a large and tedious undertaking. I don't mind spending a few months to map each field, it is just more work that I think is necessary, so any input would be greatly appreciated on how I can do this.
Also my below code does not work completely. It correctly imports the first record of text file but repeats that exact record for the remainder of rows in excel ( ie account: ABCDEF12 is repeated for 100 rows in excel rather than going down the list of records. Each new record starts 20 lines down from the previous). I am assuming that I have my loop structure wrong? Any thoughts? Any thoughts on how I can make the autofit portion of the below code more efficient? Currently it adds a lot more time to how long my code takes to parse, trim, clean and autofit, and ideas on how to shorten this?
Dim myFile As String
Dim text As String
Dim textline As String
Dim cstAct as integer
Dim actOpe as integer
Dim cusNam as integer
Dim act as integer
Dim reg as integer
myFile = "put file patch to text file here"
myFile = Application.GetOpenFilename()
Do Until EOF(1)
Line Input #1, textline
text = text & textline
Loop
cusAct = InStr(text, "ACCOUNT ")
actOpe = InStr(text, "ACCOUNT OPEN:")
reg = InStr(text, "REGION:")
cusNam = InStr(text, "CUSTOMER NAME:")
For i = 2 To ThisWorkbook.Worksheets("b2").Range("a65536").End(xlUp).Row
ThisWorkbook.Worksheets("name").Range("a" & i).Value = Mid(text, act + 6, 9)
ThisWorkbook.Worksheets("name").Range("b" & i).Value = Mid(text, cstAct + 6, 9)
ThisWorkbook.Worksheets("name").Range("c" & i).Value = Mid(text, actOpe + 13, 27)
ThisWorkbook.Worksheets("name").Range("d" & i).Value = Mid(text, cusNam + 20, 19)
next i
'here I format and autofit the cells
For x = 2 To ThisWorkbook.Worksheets("b2").Range("a65536").End(xlUp).Row
Range("a" & x).Value = Application.WorksheetFunction.Clean(trim(Range("a" & x)))
Range("b" & x).Value = Application.WorksheetFunction.Clean(trim(Range("b" & x)))
Range("c" & x).Value = Application.WorksheetFunction.Clean(trim(Range("c" & x)))
'etc etc
next x
'Text file which is parsed and then imported into excel
ACCOUNT ABCDEF12
ACCOUNT OPEN: 05/10/15 ACT TYPE: PREMIUM
CUSTOMER NAME: JOHN B. SMITH CSA REP: 154983
CUSTOMER ADDRESS: 123 SOMEWHERE DRIVE SOMETHING HERE:
LAST ORDER: 06/24/2011 COUNTRY CODE: UNITED STATES
INVOICE #: 123456789 STATE CODE: CALIFORNIA
LAST MAINTENANCE: 01/02/15 COUNTY CODE: UNCODED
SOME INDICATOR: NO COMPLAINTS: NO IPM IND: DATAPREP/PERF4
SOME INDICATOR: NO STATUS: NONE AUTO RENEW: YES
SOMETHING HERE: NO
SOMETHING HERE: ABC IND:
SOMETHING HERE: 2 ABC ASSET NO: T
.......REMAINDER OF TXT FILE REPEATS...JUST DIFFERENT RECORDS....
ACCOUNT ZXYFDG13
ACCOUNT OPEN: 05/10/15 ACT TYPE: PREMIUM
CUSTOMER NAME: JANE B. SMITH CSA REP: 154983
CUSTOMER ADDRESS: 123 SOMEWHERE DRIVE SOMETHING HERE:
LAST ORDER: 06/24/2011 COUNTRY CODE: UNITED STATES
INVOICE #: 123456789 STATE CODE: CALIFORNIA
LAST MAINTENANCE: 01/02/15 COUNTY CODE: UNCODED
SOME INDICATOR: NO COMPLAINTS: NO IPM IND: DATAPREP/PERF4
SOME INDICATOR: NO STATUS: NONE AUTO RENEW: YES
SOMETHING HERE: NO
SOMETHING HERE: ABC IND: NO
SOMETHING HERE: 2 REGION: NE
.....Records continue Indefinitely.........