excel

Excel VBA User-Defined Function to query an Access Database

萝らか妹 提交于 2021-02-11 12:48:57
问题 I have an Access 365 database that has Invoice Numbers, Due Dates, and Amounts Due. I'm trying to create an Excel UDF, whereby I input the Due Date and Invoice Number, and the function queries the database and returns the Amount Due. The formula result is #Value and there's no compiler error, though there appears to be an error when it attempts to open the record set (I set up a error message box for this action). Perhaps there's an issue with my SQL? I'd appreciate any assistance with this

Copy random 25 files from 1300 to another folder with VBA

我与影子孤独终老i 提交于 2021-02-11 12:40:41
问题 I have 1300 excel files on a server, with revenues in them. I need to compare these revenues with one pivot file to make sure the revenues are the same in the actual 2 files. Because it is on a server, opening all of them from a server would be pretty slow, thats why I want to copy a sample of them (25 excel files) to my compter first, and then run my comparison macro from this folder. But I want to make the copying process automatized, so I somehow need to select randomly 25 of these files,

Filter Criteria1 and Criteria 2 undefined on column of Dates

被刻印的时光 ゝ 提交于 2021-02-11 12:40:16
问题 According to Microsoft: https://docs.microsoft.com/en-us/office/vba/api/excel.filter.criteria2 It is possible to set a variable = .Criteria2. This throws a runtime 1004 error in Excel 2010-2019/365. Note: if the filtered column is dates, Criteria1 and Criteria2 are undefined: Application-Defined or Object-Defined Error. Note: Excel will correctly remember Criteria1 when filtering a column of text or numbers. To simplify this for reviewers, I simply recorded a macro filtering a column of dates

Filter Criteria1 and Criteria 2 undefined on column of Dates

亡梦爱人 提交于 2021-02-11 12:40:15
问题 According to Microsoft: https://docs.microsoft.com/en-us/office/vba/api/excel.filter.criteria2 It is possible to set a variable = .Criteria2. This throws a runtime 1004 error in Excel 2010-2019/365. Note: if the filtered column is dates, Criteria1 and Criteria2 are undefined: Application-Defined or Object-Defined Error. Note: Excel will correctly remember Criteria1 when filtering a column of text or numbers. To simplify this for reviewers, I simply recorded a macro filtering a column of dates

Optimal means of obtaining cell address column letter from column index and column index from column letter

帅比萌擦擦* 提交于 2021-02-11 12:38:01
问题 Typically the accepted approach is to do the following Number to Letter public function numberToLetter(ByVal i as long) as string Dim s as string: s = cells(1,i).address(false,false) numberToLetter = left(s,len(s)-1) end function Letter to Number Public Function letterToNumber(ByVal s As String) As Long letterToNumber = Range(s & 1).Column End Function However neither of these are particular optimal, as in each case we are creating an object, and then calling a property accessor on the object

VBA Excel open Word Object

五迷三道 提交于 2021-02-11 12:28:50
问题 So I have a VBA and I would like to open and modify a Word file that is embedded in the Excel instead of opening it from a folder path. I am using this VBA and it is not working properly (basically I need the VBA to open the Word document, add the table from the Excel from ranges A24:C & lastRow, copy-paste everything to an Outlook email and finally close the Word document). I receive error 13, if that helps. Please assist!!!! Thanks a lot Sub SendMail() Dim ol As Outlook.Application Dim olm

Prevent a .txt file file saving the last line as blank

夙愿已清 提交于 2021-02-11 12:28:11
问题 This is what I have. When this saves to .txt file I would like for the last line to be the last line of text not the open line below it. Please help! Thank you. Sub ExportColB() Dim myFileName As String, rng As Range, txt As String myFileName = Application.GetSaveAsFilename(fileFilter:="Text Files (*.txt), *.txt") If myFileName = "" Then Exit Sub With Range("d3", Range("d" & Rows.Count).End(xlUp)) If .Count < 2 Then txt = .Value Else txt = Join(Evaluate("transpose(" & _ .Address(external:

Prevent a .txt file file saving the last line as blank

走远了吗. 提交于 2021-02-11 12:25:06
问题 This is what I have. When this saves to .txt file I would like for the last line to be the last line of text not the open line below it. Please help! Thank you. Sub ExportColB() Dim myFileName As String, rng As Range, txt As String myFileName = Application.GetSaveAsFilename(fileFilter:="Text Files (*.txt), *.txt") If myFileName = "" Then Exit Sub With Range("d3", Range("d" & Rows.Count).End(xlUp)) If .Count < 2 Then txt = .Value Else txt = Join(Evaluate("transpose(" & _ .Address(external:

Excel Formula separate the left numeric values from the data

ぐ巨炮叔叔 提交于 2021-02-11 12:22:40
问题 I have some data in Col"K" where from i am just trying to get the left characters as i tried in Col"H" using formula. But what i used is Left function like =Function(cell,10) that is not the correct way characters can be more than 10 or less than 10. 1st formula should be dynamic to get the left numeric values. 2nd Formula should copy and paste the same numeric values until next value comes as available in Col"I" I tried to make it but what i can do is to create left function and do not know

How to fix “Run time error '-2147417848(80010108) Method 'Range' of Object _ Worksheet' Failed” caused by code within a worksheet

匆匆过客 提交于 2021-02-11 12:22:33
问题 I'm writing a code that calculate number automatically every time you edit a sheet. But somehow the code I wrote is not functioning properly that it gives a run-time error. I checked the cells and range but they are all valid and correct. All of the inputs and variables involved are simple integers (no more than 3 digits). I just got a work assignment to automate some excel sheets at work and I just learned vba from ground up recently. Private Sub Worksheet_Change(ByVal Target As Range) Dim A