My macro pulls data from a set of files in a folder and creates an output based on my formatting rules.
Ran into 2 issues though. The first being is after this macro is run it saves a file in the folder with the name "Data Export" and before I had it do this if "Data Export" was already there
Code: 'Check if file name to save exists If Dir$(vFolder & "" & sSubFolder & ".xls", vbNormal) = "" Then wb.SaveAs vFolder & "" & sSubFolder & ".xls" MsgBox "Complete!", vbOKOnly Else MsgBox "File already exists, could not save!", vbInformation, "COMPLETE!" End If
What I want it to do instead is change itself and save it as Data Export A, and then also loop for A each time, if A is there go to B , so on and so forth.
-Alternate solution if this is way to challenging, can I have it pop up the Save Message box to let the user try a new name if "Data Export" exists. I was trying to think through that too..
2nd Issue is when I loop the files in the folder I selected in my macro, I want it to ignore "Data Export" files. Before I just took a shortcut and had it save outside of the data folder, which was fine but now we are running on so many files a day that we need it inside the same folder for organization purposes.
That is done with the following
Code: 'Loop through files in folder sFileName = Dir$(vFolder & "") Do Until sFileName = ""
I was thinking maybe I can add an error handler to the loop? Before Do Until? Something like this? But how I can add it into the loop?
Does anyone have SIMPLE code for this that can be run in a normal Sub. My worksheet will always be named "Cleaned". I have seen some posts regarding Functions and other things that seem more complicated than necessary.
i would like to write into a macro the ability to check and see if a sheet named "Pie Chart" exists, and if it does delete it without being prompted whether or not i want to delete it.
How do I delete a worksheet but ONLY if it exists, if it doesn't exist, ignore the command. I'm afraid to mess up the other code in the macro/sub, so here it is...
I have some code that works almost perfectly. I am trying to automatically delete rows in which no data exists in cells in a certain column.
the problem that I am having is that is seems to go into an infinite loop.
For example, if I delete row 5 and then iterate to the next row, row 5 becomes what used to be row 6 and now my code is on row 6...essentially skipping a row.
Here is an example data set (note that the set is for 20 rows): 1 3 6
15
36 37
here is the Sub Macro2()
r = 20 Min = 1 Do While r >= Min If Cells(r, 1) = "" Then Cells(r, 1).EntireRow.Delete Else r = r - 1 End If Loop
I can delete Sheet5 using this macro. I would like to put this in the workbook so that when I close the workbook it will be activated if Sheet5 exists. If Sheet5 does not exist nothing will happen.
Sub DeleteSheet5 () Application.DisplayAlerts = False Sheets("Sheet5").Delete Application.DisplayAlerts = True End Sub
how to mark the post as solved other than go advanced and selecting solved from the drop down menu can you tell me how?
I'm trying to check if a named range "ActiveCells" exists before deleting it in VBA but can't seem to get the syntax right, I have tried: If Range("Activecells") Is Nothing Then Resume Next Else: ActiveWorkbook.Names("ActiveCells").Delete
AND
If ActiveWorkbook.Names("Activecells") Is Nothing Then Resume Next Else: ActiveWorkbook.Names("ActiveCells").Delete
Can anyone point me in the right direction? I have tried searching but I can only find threads about checking for named objects or about using the toolbars to add/delete named ranges.
Through excel I run a dos program which spits out a results file and my macro then opens this file in excel. The only problem is the macro tries to open the file before the other program has writen it. I have tried to fix this using the
I have the following code, but it takes longer than expected to run. Is there anyway to speed this up? I am not sure if autofilter is a option. I just want to search through range A16:Z16 and if the word "FALSE" exists delete the entire column. The word "TRUE" is the only other word that would exist in range A16:Z16
Is there a way to test (from Excel 2002) whether a specified file (not necessarily an Excel file) exists on my computer? I could specify the complete path.
I am using the following VB code to check if a file exists and if so add a formula in my workbook providing data from that file.
I have pre-pulled raw data in the directory "H:BusinessRptTest for scripts" which is named firstly by the day of the month and then what data it is. - i.e/ 13_CAI_AgentStats.xls
The idea of my code is to check firstly whether the file exists (i.e has the data been pulled yet) and then if so to extract the data I need from the correct sheet and if not to add a zero instead.
I thought all was ok, but if the raw workbook is not open I get a #REF error.
I have looked at some posts for getting info from a closed workbook on this site but I can't get my head around incorporating them into my code!
Code listed below
Sub Check_File_Exists()
For date_test = 1 To 31
If Dir("H:BusinessRptTest for scripts" & date_test & "_CAI_AgentStats.xls") "" Then
Select Case True Case True If wbEXT = "C:KPI 0015 external Shortageswk" & CStr(VBAWeekNum(Now(), 1)) >= 0 And _ wbINT = "C:KPI 0044 internal Shortageswk" & CStr(VBAWeekNum(Now(), 1)) >= 0 Then Case False varAnswer = MsgBox("KPI Current week No missing", vbOK, "Warning") If varAnswer = vbOK Then Exit Sub End If End If End Select
rest of code here
basically if current week files exist carry on , if they dont then pull up a msgbox with ok button to stop sub
I have written a macro to select a range of cells one by one and open the excel files mentioned in them and execute a task. It works fine. But I want the system to see if the file exists in its folder or if the file is password protected (for opening). Either of the case the file should be skipped without a warning message and any attempt to open. I need a macro for that. Following is the way the cell contents are
I:ORDERSS-S 10ALIYAMARKET ORDERSADDADD-LADIES-LEGGINGS-13246.xls I:ORDERSS-S 10ALIYAMARKET ORDERSADDADD-LADIES-PANTS-13247.xls I:ORDERSS-S 10ALIYAMARKET ORDERSADDADD-LADIES-SHORTS-13244.xls I:ORDERSS-S 10MICHELLEGAMESWORLDWIDE COMPANYWORLDWIDE COMPANY - GAMES - 10014.xls
And following is the VBA code I wrote. It it almost stops when reaching a non-existing file name
I have a workbook that links to four files. I would like to automatically update the links when the file is opened and if the linked files are not available, don't display a message.
I got the first part done using the Options menu in Excel but can't figure out how to suppress the message when the linked files are not available
I have an Excel sheet that I convert to PDF --here is Example of the name after PDF creates"Morning Report_08.16.14" , When it runs it just overwrites the file automatically if one was already on that date - I would like it to prompt to overwrite & if they choose 'yes' to overwrite the file and if not they can change the name If the new one is in addition to the one that already exists and I want it to save the new file with in the same folder.
Also when the current code is run if the PDF was left opened it stops the macro - Is it possible to see if that file is open and if so close it down so the code will work or is it possible to overwrite the file when open.
I'm having a slight problem with this script. What I'm looking to do is before the workbook is closed is check to see if the workbook already exisits on the users desktop if it doesnt then save it to the users desktop. if is does exists then just exit the sub. Here is what I have so far but for some reason it kept displaying the aleart message that the file already exists and wants to save it again.
I just added the displayalerts = false in but the script still does not know that file already exists. So when the file is closed it keeps saying file has been placed on your desktop.
I have a spreadsheet which contains 30,000 lines Column A contains an email address. This spreadsheet was merged from several and so I know that there are duplicates in it.
How can I look up column A and if an identical value (email address) is found further down the sheet on another row. Delete that duplicate row?
I'm not concerned that the data may not be identical in other columns. If the email is a duplicate delete the next and all other rows that contain that email address.
I have a spreadsheet where I want to require certain fields to be completed then I want to have that file auto emailed. I have learned that I do need to have the file saved before sending otherwise the data will not appear in the email, so with this I want to have the file temporarily saved emailed then the temp file deleted.
Here is the code I have so far but it errors on the blue text, I did change the TempFileName from = "Copy of " & wb1.Name & " " & Format(Now, "dd-mmm-yy h-mm-ss") to = [C16] & "_" & [B6] & "_" & [D6]
Private Sub CommandButton1_Click() If Range("B6").Value = "" Or _ Range("d6").Value = "" Or _ Range("f6").Value = "" Or _ Range("E9").Value = "" Or _
I have created an AddIn with code for menu buttons. When I delete the .xlb file it is replace with one about 12 KB. After some use it starts growing. One station had it to 1 meg. Could this increasing file cause problems for the code? If so, is there a way to keep it from growing?