I exported a list of data in columns from excel into a .txt file, but I'm having a hard time figuring out how to get all the columns to line up. Right now, the data looks like this:
C5H12N+ 8.609640E+01 1.30E+04 8.6096970E+01 -5.70E-04
C4H11N2+ 8.709170E+01 7.20E+02 8.7092215E+01 -5.15E-04
C3H10N3+ 8.808690E+01 1.10E+03 8.8087460E+01 -5.60E-04
C5H14N+ 8.811210E+01 2.90E+03 8.8112620E+01 -5.20E-04
C4H13N2+ 8.910730E+01 2.30E+02 8.9107865E+01 -5.65E-04
C6H8N+ 9.406510E+01 2.70E+02 9.4065670E+01 -5.70E-04
C5H7N2+ 9.506040E+01 1.60E+02 9.5060915E+01 -5.15E-04
With the longer chemical formulas, the numbers following don't line up. How can I fix this?
Output will not line up nicely in a text file. However, you could try modifying your excel columns before exporting as csv. Are you okay with padding values with spaces?
For example, changing "1.30E+04" to "1.30E+04 spacespacespaceetc"?
Here's a formula that would make each cell 20-width by padding with spaces until reaching 20, and will also trim at 20. Use for every cell.
=LEFT(B2 & REPT(" ",20),20)
This is how it would appear in a text editor:
I learned in this SO post about using XLSXWriter to add a =FILTER() function to a workbook.
Now I'm trying to add a =SORT() function. So far I have tried this:
worksheet.write_array_formula('H2', '=_xlfn._xlws.SORT(A2:F16, 6, -1)')
...but SORT doesn't appear to be an array formula. I have also tried this:
worksheet.write_formula('H2', '=_xlfn.SORT(A2:F16, 6, -1)')
worksheet.write_formula('H2', '=_xlfn._xlws.SORT(A2:F16, 6, -1)')
The formula appears in the worksheet, but instead of being:
=SORT(A2:F16, 6, -1)
...it appears as:
=#SORT(A2:F16, 6, -1)
How can I correct this?
This is similar to the other answer that you linked to and your first attempt is almost correct. I think you just need to specify a range that the range formula applies to like this:
import xlsxwriter
workbook = xlsxwriter.Workbook('test.xlsx')
worksheet = workbook.add_worksheet()
worksheet.write_array_formula('H2:M16',
'=_xlfn._xlws.SORT(A2:F16, 6, -1)')
workbook.close()
Output:
I have an issue I hope you can assist me with.
I need to copy 5 files into one, the challenge though is the files is named after the dates they were created.
eg. file names could be;
TTDU 20191113 (for today).
TTDU 20191112
TTDU 20191111
etc.
(TTDU is name of the report and will never change)
Is there a way to create a line of code, where it subtracts -1 day from file name? And can it work for workdays and not include weekend?
Or maybe you have an idea how to do it in another way
Thanks a lot!
Something along these lines, using split and mid
Called like so
SortDateOut("TTDU 20191123")
Function SortDateOut(strInput As String) As Date
Dim s As String
s = Split(strInput, Chr(32))(1)
SortDateOut = DateSerial(Mid(s, 1, 4), Mid(s, 5, 2), Mid(s, 7, 2))
End Function
Activesheet.Rows.Item(1).Delete;
The above line will delete first row in the active excel sheet.
I want to delete multiple rows so I used the following line, but it did not work.
Activesheet.Rows.Item([1,2,5,64]).Delete;
If you want a full Matlab approach you could try this out:
rows_to_delete = [1 2 5 64];
data = xlsread(file_path);
data(rows_to_delete,:) = [];
delete(file_path);
xlswrite(file_path,data);
Using Excel COM:
Activesheet.Rows('1, 2, 5, 64').EntireRow.Delete
or:
Activesheet.Range('1, 2, 5, 64').Rows.EntireRow.Delete
You could even try a more consistent notation, eventually, using 1:1, 2:2, 5:5, 64:64 instead of 1, 2, 5, 64. But I always used the latter without problems in my code.
Document: https://docs.google.com/spreadsheets/d/1N4cGw5eUq_3gCJh1w39qVatX9KV1_Hr-AqRHj_nbckA/edit#gid=1770960621
Question
How can I convert the following simple formulas at Schedule!C20:I29 into a single, simple ARRAYFORMULA at Schedule!C20?
=Count(Filter(Students!$B$5:$B, Find(C6, Filter(Students!$J$5:$O,Students!$J$4:$O$4 = 'Current Class'!$B$3))))
.
NOTE:
The above code is only a partial solution. I will substitute the ARRAYFORMULA version of the code into the correct part of the code at Current Class!L6
The C6 reference above can take on any cell between Schedule!C6:I15. I have named that range Timetable_Code. I thought I could do the following, but I was wrong...
=Arrayformula(Count(Filter(Students!$B$5:$B, Find(Timetable_Code, Filter(Students!$J$5:$O,Students!$J$4:$O$4 = 'Current Class'!$B$3)))))
Background
Originally, I created a table that now resides at 1st Version - Current Class!L6. This tab is only for your reference and will be deleted soon. Each cell has a formula with a slight modification. This formula works correctly; however, it is a behemoth and would be hard to modify...
=if(COUNTIF(Meta!$B$5:$B, CONCATENATE("=",if(L$5 = "THURSDAY", "TH", if(L$5 = "SUNDAY", "SU", left(L$5,1))), if(left($K6, 2) = "12", 0, left($K6, 1)))), CONCATENATE(if(L$5 = "THURSDAY", "TH", if(L$5 = "SUNDAY", "SU", left(L$5,1))), if(left($K6, 2) = "12", 0, left($K6, 1)), " ( ", Count(Filter(Students!$B$5:$B, Find(CONCATENATE(if(L$5 = "THURSDAY", "TH", if(L$5 = "SUNDAY", "SU", left(L$5,1))), if(left($K6, 2) = "12", 0, left($K6, 1))), Filter(Students!$J$5:$O,Students!$J$4:$O$4 = $B$3)))), " )") ,"")
.
Pros
I don't have to create any helper data.
All calculations are "in-memory"
Cons
Too large
Hard to modify
I like the output, but I don't like the cons, so I started to create a more edit-friendly version of the code that I am mostly OK with. This code is located at Current Class!L6 (and a secondary copy at Schedule!C33 - it will be deleted.) It has a single formula at Current Class!L6...
=arrayformula(if(COUNTIF(Meta!$B$5:$B, ("=" & Timetable_Code)), (Timetable_Code & " ( " & Timetable_StudentCount & " )") ,""))
.
Pros
Very easy to understand
Very easy to modify
No need to copy formula over to other cells
Cons
Two ( 2 ) helper tables were created ( one of which I think is unneeded)
Again, I like the output, but I really don't like the second helper table (Schedule!C20). I feel like this table can be eliminated, but I have not been able to figure out how.
If you really want to use arrayformula, here it is. For Schedule!C20.
=arrayformula((len(concatenate(index(Students!J5:O, , match('Current Class'!$B$3, Students!J4:O4, 0))))-len(substitute(concatenate(index(Students!J5:O, , match('Current Class'!$B$3, Students!J4:O4, 0))),C6:I15,"")))/len(C6:I15))
Probably you can use filter(as you did before) instead of index & match part, but I prefer index & match and don't want to dig more. Also you can use one help cell to store filter or index & match result to shorten the formula.
The core idea is from counting occurrences of given character in a string, ie len(a1) - len(substitute(a1, .... You can find many documents about it in the net.
Anyway, if I were you, I'd be satified with the current state. Just lock and hide the help tables or sheets. Nobody cares hidden sheets and if something bad happens, you can revert any change.
After getting a good answer from #Sangbok Lee, I decided to break apart each part of the function he gave to me. While doing that I found a highly unlikely connection to some work I did in the Google Sheets last week. A helper column I had in another tab kind of did what Sangbok Lee was trying to do. All I had to do was split that helper column into two columns (1 for the previous final calculation, 1 for) and calculate an additional count column
After reworking both of our formulas, and testing the result, I found a solution that I am even more satisfied with!
=arrayformula(if(countif(Meta!$B$5:$B, (Timetable_Code)), (Timetable_Code & " ( " & vlookup(Timetable_Code, StudentCount_Lookup, 2, false) & " )") ,""))
.
Check out the differences in the Google Sheet
Look at 1st Version - Current Class!L6 tab for the 1st version
Look at Current Class!L6 for the 2nd version
Look at Current Class!U6 for the 3rd and final version
Also look at tab Meta and Schedule for the differences.
Note: Green is old data, Red is new data