macros and vba
6570 TopicsRunt-time Error 1401 When Importing a CSV file Using VBA
I am beyond frustrated that I cannot make this work. Let me explain. My spreadsheet needs to import a standard CSV file then parse that information into several different worksheets. The very first time I ran the import code it worked. The second time and every time after that it fails with the "Run-time error '1004': Application-defined or object-defined error" message. I tried this on a different computer with the same results first run it worked, every run after that it fails. Here is the code: Sub ImportCSV() Dim ws As Worksheet Dim csvFilePath As String Dim lastRow As Long ' Set the worksheet where you want to load the data Set ws = ActiveWorkbook.Sheets("Raw") ' Specify the path to your CSV file csvFilePath = "exportusers-all.csv" ' Clear existing data in the worksheet ws.Cells.Clear ' Import the CSV file With ws.QueryTables.Add(Connection:="TEXT;" & csvFilePath, Destination:=ws.Range("A1")) .TextFileParseType = xlDelimited .TextFileCommaDelimiter = True .Refresh End With End Sub This is the code I've found in numerous places when I search the internet when I search how to do it. I have tried this as a normal user and "Run as Administrator" both fail. My Trust Center > Macro Settings are as follows: Enable VBA macros - Selected Trust access to the VBA project object model - Checked The CSV file can be opened in a text editor and Excel without any issues, but if I try to import it, it fails completely. Any help or suggestions to resolve this problem would be greatly appreciated. Thanks.20Views0likes3CommentsExcel Help
Is there a way (either formula or macro /something) for the following. I have 2 different spread sheets (files) open at the same time. First is called Time Card Second is called Wages Time Card will have a staff members details as well as dates and shift times. (20 Tabs for different staff members and their details) Wages will have Tab 1 - Summary of all staff names, hourly rates, hours worked for each day and gross amounts to be paid Tab 2 - 20 payslips with the above mentioned details, but payslip style. Lets call the first person Joe Deer I need something in Time Card next or close, to this person's name, when clicking it it will jump to his payslip in Wages sheet As mentioned. Formula or macro.. Guess anything will do. Thanks106Views1like4CommentsExcel Macros Spreadsheets Not Loading
I've spent some time with Microsoft Support (almost 3 hours, including uninstalling my MS 365 and reinstalling it), but I'm having an issue with my Excel Macro spreadsheets not loading at all. This is what I get each time. Also having an issue with non-Macro spreadsheets that I'm unable to use the Bold, Italic, and Underline functions (get the spinning wheel and then Excel Not Responding), as well as not able to use the Format function (get the same spinning wheel and then Excel Not Responding). I've been using these same Excel Macro Spreadsheets for over 15 years. Please help!220Views1like2CommentsGetting data from Snowflake to Excel
Hello I have multiple no technical users and am trying to find a way to setup a snowflake query for them and then let them refresh it whenever they want or on a schedule, but I couldn't find a good solution this what i found so far: ODBC (Not great for non technical users needs setup on each user desktop) Power Automate (Needs Power Automate Premium which we don't have) Third Party tools (Expensive pricing models) Through Power BI (We want to separate this process from power bi) Any suggested solution please!Solved100Views0likes3CommentsPivot Table
Hi everyone, I have an issue with the pivot table. There are filters from slicers and row labels in the table; when I double-click on any category from the table to see the filtered data, Excel fetches all data, not just what I filter on. Like below, I filtered from the slicer, and from the row labels, (Bills) should be between 100,000 and 200,000. I would like to see the (Bills) for (Central) in the (Start), but it gives me 632,478 and bills less than 100,000 and 200,000, not the 3 clients. Even if I tried from (In Progress), it's the same; it brings all data. The issue is only with the Bills column, but other filters come up correctly115Views0likes1CommentMacros in Excel Programs
I am developing a macro enabled spreadsheet that creates a second macro enabled spreadsheet upon exit. Is there a way for the macro in my main spreadsheet to create UserForms and Modules in the second spreadsheet? My goal here is to distribute the second spreadsheet to users and their use of it will be controlled by the UserForms and macros within it.Solved142Views0likes2CommentsMacros blocked in shared OneDrive Excel workbook as untrusted source
I have a macro-enabled Excel workbook (.xlsm) stored in OneDrive and shared with another user. When they open the shared workbook in Excel Desktop, they receive the error: "Microsoft has blocked macros from running because the source of this file is untrusted." We've already tried enabling macros in Trust Center, adding Trusted Locations, and opening the file from a synced OneDrive folder rather than Excel Online, but the error persists. Since downloading the file creates a separate copy and defeats the purpose of a shared workbook, what is the correct way to allow VBA macros to run in a shared OneDrive-hosted workbook while keeping everyone working from the same file?146Views0likes1CommentExcel Macro Creating a New Macro Enabled Spreadsheet
I have a macro enabled spreadsheet. I have a macro in this spreadsheet that is trying to create another macro enabled spreadsheet. I can create this new spreadsheet and save it as a .xlsm file. However, I want to give this spreadsheet a name and transfer data to it by toggling between my two sheets (Windows(Filename).Activate) and not save it until I am done. My problem is that the only way I have found to name it is with SaveAs statement. If I could find out what name Excel assigned to this workbood when I created it, I could work with it - but I have not found a way to do that. If the above is confusing, I am sorry. In simple terms, I want my macro to create another macro enabled spreadsheet, name it, work with it and Save it without using SaveAs. I can provide code, but I thought I would start with this.Solved95Views0likes2CommentsSeries fill a formula down a column automatically skipping a set number of rows
I am trying to fill a formula down a column every 6th row but incrementing the variable in the formula ($A2) for each entry. The formula uses the Take command and inputs 5 rows of data, so to keep it from "spilling" I need the formula to increment every 6 rows, having one blank row between each section. I have been able to accomplish "copying" it each 6th row with VBA #1 and filling the series with VBA #2 but can't figure out how to combine the two. Any help would be appreciated. VBA #1: Sub FillEvery6thCell() Dim ws As Worksheet Dim startRow As Long, lastRow As Long, col As String Dim formulaText As String Dim r As Long ' Set your sheet and parameters Set ws = ThisWorkbook.Sheets("Top 5 Employees") col = "A" ' Column to fill startRow = 10 ' First row to start filling lastRow = 60000 ' Last row to fill ' Get the formula from the starting cell formulaText = ws.Range(col & startRow).Formula ' Fill every 6th cell For r = startRow + 6 To lastRow Step 6 ws.Range(col & r).Formula = formulaText Next r Range("A2:A60000" & iRow).Replace What:="@", Replacement:="", LookAt:=xlPart, _ SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _ ReplaceFormat:=False, FormulaVersion:=xlReplaceFormula2 MsgBox "Formula copied to every 6th cell in column " & col End Sub VBA #2 Sub FillFormulasDown() Dim sourceCell As Range Dim fillRange As Range ' Define the cell containing the formula Set sourceCell = Range("A2") ' Define the target range Set fillRange = Range("A2:A5000") ' Fill formulas down sourceCell.AutoFill Destination:=fillRange, Type:=xlFillSeries End Sub175Views0likes6Comments