Tag: excel vba

Excel VBA高级筛选器,筛选一切,但

假设我在国际上有一个客户数据库。 我知道我可以使用高级filter从美国复制所有客户,使用如下所示的条件: – 国家 美国 – 但是,如果我想过滤一切,但美国呢? 这可能吗? 我目前的解决方法是使用AND运算符,列出除美国以外的所有国家,这并不美观。 希望有人能帮忙,如果这是重复的,请让我知道。 我试着用excel高级filter来search“除”,“例外”,“除了”以外的其他术语,但是没有find。 谢谢,

Excel Vba:单元格中的公式值

这应该很简单。 以下是我正在使用的代码: Private Sub CommandButton23_Click() Dim linerngs As Range Dim lineitem As Range Dim lastlinerow As Long Dim TabLastRow Dim claimstab As String Dim officesrange As Range Dim office As Range officeslastrow = Sheet2.Range("A" & Rows.Count).End(xlUp).Row lastlinerow = Sheet2.Range("D" & Rows.Count).End(xlUp).Row Set officerng = Sheet2.Range("A6:A" & officeslastrow).SpecialCells(xlCellTypeConstants, 23) Set linerngs = Sheet2.Range("D7:D" & lastlinerow).SpecialCells(xlCellTypeConstants, 23) […]

Excel VBA通​​过表循环并总结值

我有这张约5万行的表格,我希望Excel能够通过并分配一个数字或字母。 基本上我试图根据他们的总和大于1,000,000来分组数据。 如果该行中的单元格A小于1,000,000,则它将转到下一行并将之前的单元格A加到当前单元格中,依此类推。 这一直持续到所有行的总和> = 1,000,000。 当发生这种情况时,一个数字被“分配”(如在行的末尾input)。 样本数据: 这是我目前的“伪”代码: For x = 2 to lastrow y = 1 If Range("A" & x).value < 1000000 Then 'I know something needs to be entered here but I don't know what Do while balance < 1000000 sumbalance = Range("A" & x) + Range("A" & x + 1) 'Until […]

在单元格中input数字,并使用2D范围在数组中search该数字

我正在协调帐户,并想知道是否有一个公式/ VBA我可以用来search某些值,因为查找function不起作用? 例如:input-54.12到一个单元格中,公式/ VBAsearch该数字的数组。 这可能会更好地解释我想要达到的目的,尽pipe比编码更多的是解释: Sub Test() Dim Value As Integer Dim Account As Range Dim Lookup As Boolean Value = Range("D8") Account = Range("E:E") Set Value = A Set Account = B ' IF A is present in B then look up = true ' if look up is true then scroll to cell […]

Excel VBA编程执行VBA

我负责logging俱乐部的收费情况,所以我决定做一个Excel的页面。 我是Excel VBA编程的新手,所以我需要一些build议。 我的想法是:如果这个人在场,但没有付钱,我只是标记一个x ,如果他在场,只要付款,我想能够标记一个N并使其popup一个msgboxpopup询问付款的价值,并直接把这个价值在一个精确的单元格在另一个页面上。 Sub Pay() Dim Pay As String Pay = InputBox("Enter A New Payment", "Payment", "Enter amount here") Range("'versement adherent'!C15").Value = Pay End Sub 所以这是我对msgbox的想法,但是它太窄了,只有在被要求时才会启动(当写入值为N的单元格时,不会自动启动),并且写入值的单元总是相同的。 Private Sub FindN(StrSearchQuery As String) Set SearchRange = Range("versement adherent!F2:Y21") FindN = StrSearchQuery Function FindAll(SearchRange As Range, LookFor As String) Dim FoundCell As Range For Each area […]

复制表格与Excel VBA

我试图从工作簿A复制一张到新添加的工作簿B.我遇到的问题是它不保留PageSetup。 新工作簿与复制的工作表不适合在一个页面上的原始来源。 我试图研究这个,但不能确定是否需要复制PageSetup中的所有属性,或者如果它应该只是复制整个工作表时才工作。 这是我的代码到目前为止: Public Sub makeCopies(ByVal seller As String) Dim thisWB As Workbook Dim newWB As Workbook Set thisWB = ActiveWorkbook Set newWB = Workbooks.Add On Error GoTo ErrorHandler: thisWB.Sheets(1).Copy Before:=newWB.Sheets(1) newWB.Activate newWB.SaveAs fileName:=seller & ".xlsx" newWB.Close thisWB.Activate Exit Sub ErrorHandler: MsgBox "Error" & Err.Number & Err.Description newWB.Close End Sub

从macros返回整数

我试图循环通过我的Excel电子表格中的特定行。 对于第一组即时尝试循环通过每3行,以查看是否隐藏和第二个循环我正在步进每2个。我基本上想要添加什么真正的通过两个循环,并返回该值。 “返回y”部分给我一个错误。 Function FindHiddenRows() As Integer Dim x As Integer Dim y As Integer y = 0 For x = 23 To 38 Step 3 If Rows("x:x").EntireRow.Hidden = False Then y = y + 1 End If Next x For x = 40 To 46 Step 2 If Rows("x:x").EntireRow.Hidden = False Then y = […]

对于Excel VBA中的每个循环,我如何引用公式中的单元格地址?

一旦公式被附加到单元格中,我最初注释掉的代码需要用户拖拽公式。 我已经修改了下面的过程,我从一个For each cell循环切换 – 可以这样做已经完成了For each循环结构? 利用Cell.address或类似的东西? 请假设我的variables都已定义。 Dim client_row As Long 'Dim v As Long Dim v As Variant Dim i As Integer i = 2 client_row = 0 LASTROW2 = Range("B" & Rows.Count).End(xlUp).Row Set rng2 = Range("N2:N" & LASTROW2) ' For Each cell In rng2 ' If cell.Offset(0, -13) <> "" Then […]

select倒数第二行以上的所有值并复制并粘贴

我正在尝试在一个过程中select倒数第二行及其上面的所有行,并复制并粘贴值。 我可以在电子表格中find最后一行并select整行,但是我很难抵消所选的行。 我得到一个错误相关的偏移量参数。 'Removes formulas above the last line in the Auto Lease Data Dim ALR As Long Dim ALR2 As Long With Sheets("Auto Lease Data") ALR = .Range("A" & .Rows.Count).End(xlUp).Row ALR2 = .Range("A" & ALR).EntireRow.Select .Range(ALR2).Offset(-1).Activate End With

特定date的数据

目标:当我在特定的单元格(“G1”)中selectdate时,表格应过滤给定date的数据。 到目前为止我所做的是: Dim Topic As String Dim finalrow As Integer Dim i As Integer 'row counter Dim C As Range, rng Dim Test1 As String 'give the output by combining all the article topics Dim selectdate As Date Sheets("Raw").Range("H2:I23").ClearContents Set selectdate = Sheets(“Sheets1”)。Range(“G1”) Set rng = Sheets("Sheet1").Range("A2:E50") 'filtering data as per today's date Range("A1").Select Selection.AutoFilter […]