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.
Related
I have created some new formulas in my excel table by modifying one of the existing sheets.After converting to google sheets, the new formulas don't seem to have converted. The old formulas were converted just fine. What could be the potential reason for this?
Example of how the formulas are appearing in google sheets (At present it shows #ERROR) :
=_xlfn.IFNA(IF(Table1319[[#This Row],[Column4]]="Distance Activity",IF(AND(ISBLANK(Table1319[[#This Row],[Column5]]),Table1319[[#This Row],[Column10]]=_xlfn.IFNA(VLOOKUP(Table1319[[#This Row],[Column6]],_S3_Transport_EF[],11,FALSE),0)),Table1319[[#This Row],[Column9]], Table1319[[#This Row],[Column9]]/IF(Table1319[[#This Row],[Column10]]="mile", _xlfn.IFNA(VLOOKUP(Table1319[[#This Row],[Column5]]&" - "&Table1319[[#This Row],[Column6]], Mobile_S1_EF[#All], 11, FALSE),1), IF(Table1319[[#This Row],[Column10]]="km", _xlfn.IFNA(VLOOKUP(Table1319[[#This Row],[Column5]]&" - "&Table1319[[#This Row],[Column6]], Mobile_S1_EF[#All], 11, FALSE),1)*1.60934, IF(Table1319[[#This Row],[Column10]]="nautical mile", _xlfn.IFNA(VLOOKUP(Table1319[[#This Row],[Column5]]&" - "&Table1319[[#This Row],[Column6]], Mobile_S1_EF[#All], 11, FALSE),1)*0.868976)))), Table1319[[#This Row],[Column9]]), "")
Here is what I wrote in Excel :
=IFNA(IF([#Column4]="Distance Activity",IF(AND(ISBLANK([#Column5]),[#Column10]=IFNA(VLOOKUP([#Column6],_S3_Transport_EF,11,FALSE),0)),[#Column9], [#Column9]/IF([#Column10]="mile", IFNA(VLOOKUP([#Column5]&" - "&[#Column6], Mobile_S1_EF[#All], 11, FALSE),1), IF([#Column10]="km", IFNA(VLOOKUP([#Column5]&" - "&[#Column6], Mobile_S1_EF[#All], 11, FALSE),1)*1.60934, IF([#Column10]="nautical mile", IFNA(VLOOKUP([#Column5]&" - "&[#Column6], Mobile_S1_EF[#All], 11, FALSE),1)*0.868976)))), [#Column9]), "")
I found the solution. It seems on of table names were not compatible with google sheets. The table name starts with underscore _S3_Transport_EF. After I changed it to S3_Transport_EF all my formulas seemed to work
Good morning, I need some advice.
First, this is my full full script. I'm iterating over a Manufacturing BOM:
I'm not the best at VBA but have put together a working script that fills the color/border for these rows based on the level. Currently I'm grouping ranges together using union in a for loop:
Case 1
If arrRngFill(1) Is Nothing Then
Set arrRngFill(1) = Range(Cells(rwCount, 1), Cells(rwCount, colLast))
Else
Set arrRngFill(1) = Union(arrRngFill(1), Range(Cells(rwCount, 1), Cells(rwCount, colLast)))
End If
'etc... for 8 levels
However, I'm iterating over 190,000 rows which GRINDS to a halt.
So, as a hacky work around I apply the formatting every 6000 loops (any more it gets slower) and clear the array:
'Do stuff and release every 6000 ticks or on last row - Union is super slow when it gets big for some reason
If releaseTick = 6000 Or lvlNext = -1 Then
If Not arrRngFill(1) Is Nothing Then Call SetFill(arrRngFill(1), RGB(44, 35, 45), RGB(0, 0, 0), RGB(0, 0, 0), True)
If Not arrRngFill(2) Is Nothing Then Call SetFill(arrRngFill(2), RGB(77, 76, 125), RGB(0, 0, 0), RGB(0, 0, 0), True)
'etc..... for 8 levels
Erase arrRngFill
releaseTick = 1
End If
My question is: Is there a cleaner way to do this without slowing down the script? My goal was to apply all the formatting at once. Having to dump out the formatting every 6000 loops seems wrong and I think I'm missing something. Currently the script takes about 5.5 seconds over 190,000 rows.
Thanks for looking!
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:
Essentially I am generating a number of charts with xlsxwriter and trying to ensure gaps appear in the chart where I have #N/A's. Unfortunately it is not possible unless the show #N/A as empty cell setting is selected (I dont believe it is a supported feature as it is relatively new for excel).
I am currently using the following code to produce the above:
from xlsxwriter.workbook import Workbook
workbook = Workbook('chart.xlsx')
worksheet = workbook.add_worksheet()
bold = workbook.add_format({'bold': True})
headings = ['Number', 'Value']
line_chart = workbook.add_chart({'type': 'line'})
line_chart.add_series({
'categories': '={1,2,3,4,5,6}',
'values': '={2,#N/A,2,3,4,#N/A}'
})
worksheet.insert_chart('F2', line_chart)
workbook.close()
I understand that if I changed it to the following, the problem would be fixed, however my aim is to use the above approach. If its not possible thats fine.
from xlsxwriter.workbook import Workbook
workbook = Workbook('chart.xlsx')
worksheet = workbook.add_worksheet()
bold = workbook.add_format({'bold': True})
headings = ['Number', 'Value']
data = [
[1, 2, 3, 4, 5, 6],
[2,'', 2, 3, 4,'=NA()'],
]
worksheet.write_row('A1', headings, bold)
worksheet.write_column('A2', data[0])
worksheet.write_column('B2', data[1])
line_chart = workbook.add_chart({'type': 'line'})
line_chart.add_series({
'categories': '=Sheet1!$A$2:$A$7',
'values': '=Sheet1!$B$2:$B$7',
})
worksheet.insert_chart('F2', line_chart)
workbook.close()
Unfortunately it is not possible unless the show #N/A as empty cell setting is selected (I dont believe it is a supported feature as it is relatively new for excel).
That is correct. It looks like that feature was added recently in Excel 16 (the XML element is <c16r3:dataDisplayOptions16>). So it isn't supported in XlsxWriter.
Note, it is possible to set the first 3 of those options using chart.show_blanks_as():
chart.show_blanks_as('span')
The available options are:
gap: Blank data is shown as a gap. The default.
zero: Blank data is displayed as zero.
span: Blank data is connected with a line.
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