Tag: excel vba

debugging一个QueryTables.Add脚本

Sub FindData() Dim accountNumber As Range Set accountNumber = Range(Range("A2"), Range("A2").End(xlDown)) Dim dataSet As QueryTable For Each Value In accountNumber Set dataSet = .QueryTables.Add( _ Connection:="URL;http://www.prad.org/CamaDisplay.aspx?OutputMode=Display&SearchType=RealEstate&ParcelID=" & Value, _ Destination:=ThisWorkbook.Worksheets(2).Range("A1")) Next Value With dataSet .RefreshOnFileOpen = False .WebFormatting = xlWebFormattingNone .BackgroundQuery = True .WebSelectionType = xlSpecifiedTables .WebTables = "3" End With With Application dataSet.Refresh BackgroundQuery:=False […]

运行时错误“1004”应用程序定义或对象定义的错误

(我知道select必须避免,即时学习,并已经得到了与其他密切相关的问题的帮助)非常感谢帮助如何重新编码以下更“宽”,现在有时运行通过,有时不运行。 现在停在第四行,标题中写有错误信息。 请记住:正如你所看到的,刷新数据库时logging的macros给出了两种不同types的代码,我猜它必须与我的数据库在运行时通过不同的excelversions进行复制? 它可以写在一个方面吗? 我可以打电话给公众吗? Sheets("DB2 Totbel").Select Selection.QueryTable.Refresh BackgroundQuery:=False Sheets("DB2 Giva").Select Selection.QueryTable.Refresh BackgroundQuery:=False Sheets("TS4LAGER").Select Selection.ListObject.QueryTable.Refresh BackgroundQuery:=False Sheets("PIX").Select Selection.ListObject.QueryTable.Refresh BackgroundQuery:=False 'Sheets("PIX").Select 'Selection.ListObject.QueryTable.Refresh BackgroundQuery:=False Sheets("OFO data").Select Selection.ListObject.QueryTable.Refresh BackgroundQuery:=False

如何使用自定义模块在数字之间添加逗号

我有一个自定义模块创build一个名为“Myvlookup”的function,其function类似于VLOOKUP,但在一个单元格中输出多个数字。 这里是代码: Function MYVLOOKUP(lookupval, lookuprange As Range, indexcol As Long) Dim r As Range Dim result As String result = "" For Each r In lookuprange If r = lookupval Then result = result & " " & r.Offset(0, indexcol – 1) End If Next r MYVLOOKUP = result End Function 这是行得通的,但我想知道我可以改变它,所以我可以在数字之间加一个逗号。 我试图在“”之间添加它,但是在第一个数字之前创build了一个逗号,并且想知道是否有添加另一个可以摆脱第一个逗号的方法。

在Excel中复制现有的表格显着减慢我的VBA代码

我一直在build立一个程序来创build发票依赖于我的公司正在与之交互的客户/业主的数量。 对于每一个客户,我们可能有多个所有者,我们所做的是为每个所有者创build一个单独的发票。 我的问题是,代码被devise为复制模板,然后相应地编辑它,这个复制过程减慢了我的代码在10到20秒之间(我在代码中有一个计时器)。 有没有其他办法可以更有效地做到这一点? 我在工作表中有一张图片,当我只是尝试创build一个新工作表,然后从模板工作表中复制/粘贴时,工作表中的图片不能很好地复制。 任何其他的想法? 谢谢! 编辑: Private Sub CommandButton1_Click() Dim t As Single t = Timer Application.ScreenUpdating = False Application.Calculation = xlCalculationManual Sheets("Client Invoice Template").Visible = True Sheets("Client Invoice Template").Visible = True Sheets("Client Invoice Template").Copy Before:=Sheets(3) Sheets("Client Invoice Template (2)").Name = "Client Invoice" Sheets("Client Invoice Template").Visible = False Sheets("Select").Select Application.Calculation = xlCalculationAutomatic MsgBox […]

分组数据表

我在Excel文件中有以下表格: customer ID sell attribute1 attribute2 attribute3 …… attribute N Customer1 sell1 1 0 1 1 Customer1 sell2 0 0 0 0 Customer1 sell3 1 0 1 1 Customer2 sell4 0 0 0 1 Customer2 sell5 1 0 1 0 Customer3 sell6 1 0 0 0 …… …… 我需要一个Excel VBA函数来删除多余的客户行,并为每个客户只产生一行代表该客户的所有列值…(每列的最大值只产生该列中的最大值),列出售其不考虑在最后的结果。 结果如下: customer ID attribute1 attribute2 […]

无法使用devise器和inputVBA代码

有人可以帮我把我的用户表单从cal工作表中提交到这个表中吗? Private Sub cmdbutton_submitform_Click() Dim emptyRow As Long 'Make Sheet2 active Sheet2.Activate 'Determine emptyRow emptyRow = WorksheetFunction.CountA(Range("A:A")) + 1 'Transfer information Cells(emptyRow, 1).Value = txtbox_number.Value Cells(emptyRow, 2).Value = txtbox_rank.Value Cells(emptyRow, 3).Value = txtbox_Name.Value Cells(emptyRow, 4).Value = txtbox_height.Value Cells(emptyRow, 5).Value = txtbox_weight.Value Cells(emptyRow, 6).Value = txtbox_right_rm.Value Cells(emptyRow, 7).Value = txtbox_left_rm.Value End Sub

如何防止Excel在粘贴时将行数据合并到单个单元格中?

我有两个电子表格,我正在复制行之间。 我有一个单独的工作簿中的macros保持打开状态,同时打开和closures包含电子表格的源和目标工作簿。 我将select目标行 rows(activecell.row).copy 然后,我将closures源工作簿,因为它的名称与目标工作簿完全相同,请在另一个文件夹中打开目标工作簿并执行 activesheet.pastespecial ' this line copied from record macro generated code 有时它可以正常工作,其他时候,源行将被挤压到行的第一个单元格中,有时我会收到一条错误消息,指出对象不支持pastespecial。 我不能告诉我是不是搞乱了副本没有指定我的意思是复制整个行,或者如果我需要以某种方式指定源数据是从另一个工作簿和粘贴function应该将数据视为行的价值的数据,而不是单个单元的价值。 如上所述,我复制了从我使用“录制macros”function生成的macrosExcel中的pastespecial行,并手动执行行复制。 万一重要,这是整个例程。 Sub copyStudentsToEmail(emailApacket) ' copies student records to email Dim cel, nameCel, sourcePath As String Rows(ActiveCell.Row).Copy sourcePath = ActiveWorkbook.FullName ActiveWorkbook.Close (True) Workbooks.Open ThisWorkbook.path & "\\email\\records.xls" ' search for bottom row Range("a1").Select While ActiveCell.Value <> "" ActiveCell.Offset(1, 0).Select […]

运行时错误1004对象“_Worksheet”的方法“范围”失败

我正在尝试将大量的工作表合并到一个新工作表中。 我真的很感激任何意见。 问题是与线: wsSrc.Range("A1", wsSrc.Range("D", lastRow)).Copy Destination:=rngDest 当我尝试运行时会导致错误。 我以前一直在使用代码将所有表单合并到工作表摘要,这是macros的button被创build的工作正常。 Sub mcrCombine() ActiveWorkbook.Sheets.Add.Name = "Combined" 'Create new sheet 'Definitions Dim wsSrc As Worksheet Dim wsDest As Worksheet Dim rngDest As Range Dim lastRow As Long Dim destRow As Long Set wsDest = Worksheets("Combined") 'Destination sheet in same Workbook Set rngDest = wsDest.Range("B1") 'Destination cell in Combined […]

VBA中的函数返回一个工作表中的#Value,但在另一个工作表中

我有一个在VBA中的函数,通过调用其他较小的函数进行一些操作。 此function在任何工作表中都不起作用,仅在一个工作表中。 在工作表中它不起作用,从另一个函数获取值时,它只是从整个algorithm中跳出来。 这是我的Function determinarCantidadPorPedido(ByVal material As String, ByVal mes As String) Dim demanda As Double Dim pProgramado As Double Dim numPedidos As Integer demanda = determinarDemanda(material, mes) Call contarProductosMateriales Sheets("LlegadaMateriales").Activate Dim fila As Integer Dim columna As Integer For i = 1 To numMateriales Step 1 If Sheets("LlegadaMateriales").Cells(1 + i, 1) = material Then […]

通过VBA添加公式会引发运行时exception

我想通过VBA添加一个公式到一个单元格,但只是得到运行时间exception1004没有进一步的信息。 Cells(4, 3).Formula = "=IF('Mustermann, Max'!C13="""";"""";""impacting team targets"")" 我的配方有什么问题吗?