Edit multiple Excel workbooks in folder - vba

I have a couple hundred CSV files I need to do the same edits to.
-I need to change one column from scientific notation to a number without and decimals
-If a cell in specific column begins with '2014', delete entire row
-Save as new file name, from 'filename.csv' to 'filename_new.csv'
I tried using Kutools for Excel but couldn't figure out if I could edit multiple books
Could someone help me out with this? I appreciate the help. Thanks.

Workbooks.Open "YourFilePath" will let you open a single file (don't forget that you'll probably need to store the workbook in a variable so you can better address it).
You can then do whatever edit you like, for example your YourSheet.Cells(x,y).EntireRow.Delete under an If condition.
You can then .Close your Workbook and specify a filename to save.
Matt, I'm sorry but I can just provide you some ideas. Writing the code won't help you learn :)

Related

Modify range of Hyperlinks in Excel

So, I have a spreadsheet that I have sent out to several of our staff asking to update certain fields/columns. I have a Document Link field (Column G) which links them a folder in our F: Drive which they can use to help populate the necessary fields.
The spreadsheets which I want them to complete are also in this F:Drive. However, I noticed each of the document links no longer work, and when I check the link under Edit Hyperlink, I notice instead of the desired "*F:\Procurement..." I have my home drive "+\NSH-HDRIVES1..." as the header,
F:\Procurement\Contracts\Alco...xxx...
\NSH-HDRIVES1\Contracts\Alco...xxx...
I have hundreds of these lines with document links that need "\NSH-HDRIVES1" replaced with "F:".
Is there some kind of VBA Macro that will let me do this? I have little experience and time to learn VBA Macros at this point so any help would be greatly appreciated. Note each link is different and goes to a different folder within our F:Drive, all I need is to change the prefix.
Thanks and sorry for any duplication.
The following code may help, but it is set up to only work on the ActiveSheet. If your hyperlinks are in multiple workbooks and multiple worksheets you will need to loop through them all.
For Each h In ActiveSheet.Hyperlinks
h.Address = Replace(h.Address, "\NSH-HDRIVES1\", "F:\Procurement\")
h.TextToDisplay = Replace(h.TextToDisplay, "\NSH-HDRIVES1\", "F:\Procurement\")
Next

How to keep the first space in Cell on a .xlt

I worked on an export of data from an ERP to Excel but I encoutered a problem.
When I received my datas on my model Excel (.xlt, i don't have a choice for the extension...), all first spaces of fields in the ERP disappeared on my worksheet...
An exemple (Here, spaces before "Holder") :
And now, on excel, without spaces... :
And the last information, I think the problem is only on file type .xlt (97/03) (The only one I can use of course...) because when I try an export in .xls, there is no problem.
I already tried to change the type of cell in Text or Standard but it doesn't work.
Did you have a solution ?
Thanks !
Let me outline a typical solution:
You have a "data source" you cannot control - in this case it's an xlt file that somewhere on your hard drive - call it export1.xlt
You want to add the data from a data source (export1.xlt) to a "database" which could just be another aggregate spreadsheet or whatever. Let's call it database1.xlsx.
Typcially you would create a marcro inside database1.xlsx that knows how to import data into intself - in this case let's say you give a path e.g. C:\temp\export1.xlt and tell it to copy that data to Sheet1.
When you run that macro it will open export1.xlt, read the data into Sheet1 of database1.xlsx, and perform any necessary post-processing.
In this case the post processing could simply be looping over every cell to looking for a missing space.

Rename Any Kind of File In Specific Part Using Excel Macro

My Question is I have a folder with a name "xyz" somewhere, for example it is on desktop and there are 2 excel files namely a,b in that xyz folder. I work in excel workbook "a" which consist of two names i,j in some cell values for example i is in cellA1, j is in A2.
Now I want to rename excel files a,b with i,j with of without opening or closing files after renaming. It is possible. If possible please post me the code. I have no code....please provide from scratch
I think you will find the answer by a simple search of previous questions. I easily found this which should get you on the right path:
Renaming files with vba

Excel VBA: Resetting spreadsheet count

I have a excel VBA macro that dynamically generates and deletes spreadsheets based on user input. However, when I open the VBA IDE, it seems that although I am naming my spreadsheets in the subs that create/delete them, the overall count is still increasing.
For example, depending on how far into execution my program is, under the "Microsoft Excel Objects" folder in my current project, the spreadsheets in the current workbook could look something like
Sheet101(Sheet3)
Sheet103(Sheet2)
Sheet104(Sheet1)
Or
Sheet81(Inputs)
Sheet83(Date Adjustment Interpolation)
Sheet84(Pricing)
Sheet85(Comparison)
No matter if I delete the rest of them and add one, it still picks up where the last highest one left off.
I don't know how many times this macro will be run and I'd feel a lot better about putting it out there if I could reset this annoying tally on the number of spreadsheets that have ever been generated, since I don't know for sure where excel will cut me off. Plus it's just annoying.
My Question:
I would like to know how to alter that spreadsheet number, or at least what the relevant object is for doing so.
Thanks!
Thanks to #dijkay s suggestion on code names, I've found some code to accomplish this.
ThisWorkbook.VBProject.VBComponents("Sheet1").name = "test"
Will change the code name of Sheet1 to test, so in the Excel Objects folder, it will appear as test(Sheet1) for example.
This option, however, requires messing around with some trust/security settings in each individual excel client running the macro, which is unsuitable for my purposes, unfortunately. You can also change the value manually by changing the (Name) property directly in the IDE through the properties window.
here are some ideas you can try...
Sheets(x).Name = "Sheet" & x
or (assuming in this example, 'Sheet3' doesn't already exist:
Set Sheet3 = sheets.Add
Sheet3.name = "Sheet3"
This is more cleanup than re-setting
cheers,
Micéal

excel macro to read text file and find matches in cells

I really could use some help
I have two .txt/csv files that I need to read from into my excel file.
In my excel file I have a whole column, each cell containing string of characters and I need to write a script to be able find matches and and copy an adjacent column from that txt file.
An example of a single row on my txt file is shown below:
"AB101AA","AB10 1AA","AB101A","AB10 1A","AB101","AB10 1","AB10","AB10","AB","10",394251,806376,,
"AB101AF","AB10 1AF","ABERDEEN","ABERDEENSHIRE",,"ABERDEEN, CITY OF"
My excel file would have a cell which probably say "AB101AF" and i want the corresponding cell to run through a million rows and find the match and then find the corresponding nth cell on the txt file and return it on the excel spreadsheet example "ABERDEEN, CITY OF".
I know I havent been helpful in explaining the issue. But any help would be appreciated.
Thank you
Depending upon the size of your text file you could import the file using the GetExternalData option in Excel. This would allow you to load your data into a different Sheet and then use a lookup to your data from the main Sheet. Using Match and/or vlookup should help here.
You could also add a workbook connection to the text file and search using the connection.