how to automatically delete specific rows in excel file? - vb.net

Situation: every 2 weeks we need to download 3 Excel workbooks from a website, each time we need to open these 3 files and delete always the same rows, for example in the first downloaded Excel workbook we need to delete the first 4 rows, in the 2nd Excel workbook we need to delete the first 4 rows and then the 6th row, etc... What would be the best way to approach this? Could this eventually be done from within a DOS batch file or a VB script? Or is something more advanced required? Any help is most appreciated.

A VB script could do it. I'd suggest you create a new workbook, and record a macro into that workbook which does what you want. Then you could put a button onto your new workbook to run the macro. As long as all workbook filenames each time and rows to be delated are identical, that should work. Bear in mind, though, that I sometimes find that it's necessary to clean up the macros that excel records, in order to make them more robust.

Related

Formatting Data in excel sheet with blue prism

I'm trying to run a duplicate check In which varying data is pulled from a website and compared to a master list, the master list being stored in Excel. The information from the website is read from a table in which has line breaks. These breaks are translated over to the data collection they are initially stored in. Some of the data from the website us eventually written to the master list in Excel. So when I read the master list back into Blue Prism to run a duplicate check, the rows that have line breaks are written into a collection as multiple rows (ex. I should have on 7 rows in my collections but am getting 42). Since the rows are not EXACTLY the same between the 2 collections, when it runs the automation does not recognize the duplicates.
The easiest way to solve this would be if I could make the collection rows have no line breaks as soon as the data is read. I've attempted to use the calculation stage to do so with no luck. I'm not sure if it is actually possible to do this, but would appreciate any direction.
Record an Excel macro to do the data sorting/cleaning in Excel (possibly Text To Columns, etc..) and then include the running of the macro as part of your Blue Prism process by using an action stage and the MS Excel VBO - Run Macro. Get the process to create an Excel instance (and create a handle data item from that stage), then use Open Workbook (whatever workbook you store your Macro in) and then use the MS Excel VBO - Run Macro (use the same handle created earlier and type in the name of the "macro").
It sounds like what is happening is that the MS Excel VBO is grabbing the data from the Excel Worksheet wholesale.
This is to say that it's accessing your Worksheet table, copying the cell values BUT not the cell formatting data, and then dumping the values into a BP collection.
Since it did not bring along any of the original cell formatting data to reference when it went to populate the collection it's just breaking up the values based on crturn/line breaks. Thus, your collection is organized based on that, and not on the original Worksheet cell.
So, with that said, on to a solution!
Solution 1
Brute force the organization of the incoming Excel cell data to the collection by looping over the Excel Worksheet cell-by-cell.
Run a loop, and in that loop have BP go into the Excel Worksheet and grab the first populated cell it comes across. Run a formatting/cleanup Calculation stage over the data. Dump the cell value into a single collection field.
Repeat.
This is...inelegant, expensive at best, and not at all recommended for any medium to large dataset. But it's definitely the best way to do string manipulation and value comparisons before it hits your collection. Since it sounds like your using a Master template then you as-well know what the expected format of your data should be.
This method will enable you implement Trim(), Concat(), or Split() in a Calculation stage to better organize your incoming data before you dump it into a collection.
This is also basically what I think you're already trying to do, but cell-by-cell instead of Worksheet row-by-row or table-by-table.
Solution 2
Clean up the table data you grab from the website before you dump it into the Excel Worksheet.
This is basically Solution 1, but in reverse. Simply format/cleanup your data before it hits you Excel Worksheet.
I'm not sure this is any better than Solution 1, but, you know, it's something...
Solution 3
Format the cell data IN the MS Excel Worksheet itself.
Basically rearrange the cells and cell data in the Excel Worksheet into a more predictable format by using the Split, Trim, Merge, or other actions included in the MS Excel VBO. You can also do this using the Data - OLEDB utility object, but that requires some pretty solid understanding of SQL syntax.
This would look like this using the MS Excel VBO:
Grab the Excel Worksheet data wholesale and dump into a collection
Count the rows/fields of the collection
Is that number consistent with the desired/expected format of your data?
If not, have the bot go back into the Excel Worksheet and reformat the cells by removing any carriage returns/line breaks/whatever else
Repeat.
However, I'm always reluctant to reformat any original source, as it's then hard to figure out what wrong and where it went wrong when you've changed the original structure of your data. So it's best to always make a copy of the Worksheet before you make any manipulation.
Unfortunately I don't have access to my BP environment at the moment or I'd provide you with the act object actions you'd need to do any of this, my bad. Once I do I'll update this answer.

Changing a file location for 10,000+ cells in Excel

I'm creating a workbook in Excel, and need it to reference other workbooks. I am pulling information from about 30 cells for each day of the year. Each day of the year is a separate workbook. So, I have over 10,000 cells that I need to change if I just copy and paste the formulas for each day.
The reference I have right now is something like this:
='C:\user\data\year\[day.xlsx]Sheet1'!A1)
Where that A1 will be replaced by 30 other cells, and the day.xlsx will be replaced with all of the days in a year. For everything I've tried so far Excel has asked me to manually locate each file per cell.
Is there any way to make this process quicker than manually changing the file name for every single one of these cells? Maybe be able to set the date in the file name to a variable that will link to a cell?
Any guidance would be appreciated. Thank you.
To summarize: You want to create addresses in the stated format by string manipulation and then query their value.
There is in fact a function for this, it is called INDIRECT. Unfortunately it requires the source file to be open for external references, so I'm not sure if it is any help to you. I have never tried to open 365 excel files at once.
See also this question on that topic.
If you do not wish to open all the files by hand you will probably have to fall back on VBA (or perhaps JavaScript if you use Office 2016). It shouldn't be to difficult to create a macro which generates the references for you.
Here is a starting point for such a macro:
Sub Makro1()
Dim day As Integer
For day = 1 To 365
Cells(day, 1).FormulaR1C1 = "='[BASENAME" & day & ".xlsx]SHEETNAME'!R1C1"
Next i
End Sub
One more thing: After that your workbook will be linked to all those day-files. As such it will reflect changes as they occur in the day-files. If that is not required it would probably be best to sever the connections and replace each reference with its value. You can do that via Data->Queries&Connections->Manage Links->sever connection (I'm translating from my localized excel version so the exact names may vary) OR you can just copy every thing and then paste only values.

Automated formatting CSV files using an Add-In in Excel 2010

I have a C program that generates CSV files as output.
For example - I have 12 CSV files; one for each month. First column is Employee Name and Second column is their respective salaries. Assume there are 10 employees.
I want to format the 'salaries'column such that if a cell has a value over 10,000, the text should become green. Else it should remain blue. I have been able to do this using VBA for one file by adding a Command Button in the file and writing a small script.
However the issue is, every time I run my C code, it will generate a new set of CSVs; overwriting the existing ones. Besides, I want to apply such formatting to other CSV files I intend to generate.
I read that a .xla Add-In (which can exist on its own unlike embedded VBA macros in an Excel sheet) might be the solution.
I have 2 questions -
1. Is it possible to do with Add-Ins?
2. If yes, then I wanted to create a single batch file which would first generate the CSVs, and then run the Add-In on it. Is that possible too?
Thank You.

Excel: How to compare sheets from 2 different workbooks for differences

I have an original excel file that I have ran a simulation that inputs financial data. I made a copy of this file, and wired the formulas up differently to try and increase calculation performances.
I now have 2 workbooks, the original and the final. I want to compare each sheet from each of the workbooks together to make sure that the financial numbers have remained the same, to make sure the new formulas are not effecting the numbers received.
I have tried to put copies of the two sheets into one workbook, name them April12 and April15. Then insert a third sheet. In cell A1 of the third sheet, I wanted to use the formula
=April12!A1=April15!A1
to get TRUE/FALSE values. But the formulas in these sheets reference many other sheets that are not in this new workbook, so all of my numbers turn up as #REF.
Iv googled many different ways of approaching this but I cant seem to get any of them to work. Does anyone know a simple way I can compare just the values from 2 sheets from 2 different workbooks to find out if the numbers have remained the same or have changed?
Note:I am using excel 2010.
I think you already know how to verify data using formula so is the problem to refer to a row in a different workbook ? if so, following might be helpful :
=[yourFile.xls]SheetName!$Col$Row
this way you can update your formula like(yourFile.xls refers to the complete path including the file name) :
=[file1.xls]April12!A1=[file2.xls]April15!A1

VBA script to copy specific rows in Excel from a given workbook to a new workbook if specific value is found in a given column

I have been looking for a solution to my problem for the past 48 hours and I couldn't find anything. Keep in mind I have very basic programming knowledge and I might have overlooked something to fit my needs without understanding the code behind it.
I have an excel workbook with a sheet containing all of the data.
It's a list of shipments going in and out of a port.
Now when something is loaded, a "Date Loaded" cell is populated with the date automatically.
What I need for every row that has a blank "Date Loaded" cell to be copied to a new workbook which will be named by the date it was generated (i.e.:031814-PM) depending on the time of the day, PM could be AM.
Now I might not need all the columns to be copied to the new workbook. I need a way to exclude those columns during the copying process.
I want the VBA script to be called with a button that will be at the top of the data worksheet so that when we click on it, the new workbook is generated.