- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我很抱歉提出类似的问题,但我遇到了一个问题,bcs 我不知道很好的 VBA 编码......
我发现了许多类似的问题,并且找到了可以满足我需求的代码。
I found code here 但我不知道如何编辑该代码以便他可以在我的工作簿中工作。我有 35 个工作表的工作簿,格式相同,值在“A:F”列中,在“E”列中我有文本“库存”和“已发送”,我想要所有工作表中的所有行“E”列中的“库存”值将被复制到一个名为“空白列表”的工作表中。我试图自己编辑代码,但它无法运行,没有任何 react 。提前致谢。
编辑代码
Sub CommandButton4_Click()
Dim wM As Worksheet, ws As Worksheet
Dim r As Long, lr As Long, nr As Long, y As Long
Dim c As Range, firstaddress As String
Application.ScreenUpdating = False
Set wM = Sheets("Blanko List")
lr = wM.Cells.Find("*", , xlValues, xlWhole, xlByRows, xlPrevious, False).Row
If lr > 1 Then wM.Range("A2:G" & lr).ClearContents
For Each ws In ThisWorkbook.Worksheets
If ws.Name <> "Blanko List" Then
y = 0
On Error Resume Next
y = Application.CountIf(ws.Columns(7), "On Stock")
On Error GoTo 0
If y > 1 Then
firstaddress = ""
With ws.Columns(7)
Set c = .Find("On Stock", LookIn:=xlValues, LookAt:=xlWhole)
If Not c Is Nothing Then
firstaddress = c.Address
Do
nr = wM.Range("G" & Rows.Count).End(xlUp).Offset(1).Row
ws.Range("A" & c.Row & ":G" & c.Row).Copy wM.Range("A" & nr)
Application.CutCopyMode = False
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address <> firstaddress
End If
End With
End If
End If
Next ws
wM.Activate
Application.ScreenUpdating = True
''''
Original code:
Option Explicit
Sub GetYes()
Dim wM As Worksheet, ws As Worksheet
Dim r As Long, lr As Long, nr As Long, y As Long
Dim c As Range, firstaddress As String
Application.ScreenUpdating = False
Set wM = Sheets("Master")
lr = wM.Cells.Find("*", , xlValues, xlWhole, xlByRows, xlPrevious, False).Row
If lr > 1 Then wM.Range("A2:G" & lr).ClearContents
For Each ws In ThisWorkbook.Worksheets
If ws.Name <> "Master" Then
y = 0
On Error Resume Next
y = Application.CountIf(ws.Columns(7), "Yes")
On Error GoTo 0
If y > 1 Then
firstaddress = ""
With ws.Columns(7)
Set c = .Find("Yes", LookIn:=xlValues, LookAt:=xlWhole)
If Not c Is Nothing Then
firstaddress = c.Address
Do
nr = wM.Range("G" & Rows.Count).End(xlUp).Offset(1).Row
ws.Range("A" & c.Row & ":G" & c.Row).Copy wM.Range("A" & nr)
Application.CutCopyMode = False
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address <> firstaddress
End If
End With
End If
End If
Next ws
wM.Activate
Application.ScreenUpdating = True
End Sub
最佳答案
复制标准行
Option Explicit
Sub CopyCriteriaRows()
' Source
Const sCols As String = "A:F"
Const sfRow As Long = 2
Const scCol As Long = 5
Const sCriteria As String = "On Stock"
' Destination
Const dName As String = "Blanco List"
Const dFirst As String = "A2"
' Exceptions
Const ExceptionsList As String = "Blanco List" ' add more
Const ListSeparator As String = ","
' Workbook
Dim wb As Workbook: Set wb = ThisWorkbook ' workbook containing this code
' Write the names of the worksheets to be 'processed' to an array.
Dim wsNames As Variant
wsNames = ArrWorksheetNames(wb, ExceptionsList, ListSeparator)
If IsEmpty(wsNames) Then Exit Sub ' no worksheet found
' Create a reference to the first destination row range.
' Note that the number of columns is equal in source and destination.
Dim dws As Worksheet: Set dws = wb.Worksheets(dName)
Dim cCount As Long: cCount = dws.Columns(sCols).Columns.Count
Dim drrg As Range: Set drrg = dws.Range(dFirst).Resize(, cCount)
Dim sws As Worksheet ' Source Worksheet
Dim srg As Range ' Source Range
Dim sfrrg As Range ' Source First Row Range
Dim drg As Range ' Destination Range
Dim Data As Variant ' Data Array
Dim cValue As Variant ' Current Value
Dim dr As Long ' Destination Row Counter
Dim sr As Long ' Source Row Counter
Dim c As Long ' Column Counter
For Each sws In wb.Worksheets(wsNames)
' Create a reference to the current Source First Row Range.
Set sfrrg = sws.Columns(sCols).Rows(sfRow)
Set srg = Nothing
' Create a reference to the current Source Range.
Set srg = RefColumns(sfrrg)
If Not srg Is Nothing Then ' the current Source Range is not empty
' Write the values from the current Source Range to the Data Array.
Data = GetRange(srg)
' Write the matches to the top of the Data Array. The size
' of the array stays the same but 'dr' is used: to track
' the number of, to move, and finally, to write (to the worksheet)
' the 'destination' values.
dr = 0
For sr = 1 To UBound(Data, 1)
cValue = Data(sr, scCol)
If StrComp(CStr(cValue), sCriteria, vbTextCompare) = 0 Then
dr = dr + 1
For c = 1 To cCount
Data(dr, c) = Data(sr, c)
Next c
End If
Next sr
If dr > 0 Then ' there have been matches
' Create a reference to the Destination Range.
Set drg = drrg.Resize(dr)
' Write only the 'destination' values (dr) from
' the Data Array to the Destination Range.
drg.Value = Data
' Create a reference to the next Destination First Row Range.
Set drrg = drrg.Offset(dr)
End If
End If
Next sws
' The 'Clear Range' is the range spanning
' from the last 'Destination First Row Range'
' (which was referenced, but was not written to)
' to the bottom-most row range of the worksheet.
Dim crg As Range
Set crg = drrg.Resize(dws.Rows.Count - drrg.Row + 1)
crg.ClearContents
End Sub
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Purpose: Returns the names of the worksheets of a workbook ('wb'),
' that are not included in a list ('ExceptionsList'),
' in an array.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Function ArrWorksheetNames( _
ByVal wb As Workbook, _
Optional ByVal ExceptionsList As String = "", _
Optional ByVal ListSeparator As String = ",", _
Optional ByVal FirstIndex As Long = 0) _
As Variant
If wb Is Nothing Then Exit Function
Dim wsCount As Long: wsCount = wb.Worksheets.Count
If wsCount = 0 Then Exit Function ' There could e.g. only be charts.
Dim IndexDiff As Long: IndexDiff = FirstIndex - 1
Dim LastIndex As Long: LastIndex = wsCount + IndexDiff
Dim Arr() As String: ReDim Arr(FirstIndex To LastIndex)
Dim n As Long: n = IndexDiff
Dim ws As Worksheet
If Len(ExceptionsList) = 0 Then
For Each ws In wb.Worksheets
n = n + 1
Arr(n) = ws.Name
Next ws
Else
Dim Exceptions() As String
Exceptions = Split(ExceptionsList, ListSeparator)
For Each ws In wb.Worksheets
If IsError(Application.Match(ws.Name, Exceptions, 0)) Then
n = n + 1
Arr(n) = ws.Name
End If
Next ws
End If
Select Case n
Case IndexDiff
Exit Function
Case Is < LastIndex
ReDim Preserve Arr(FirstIndex To n)
End Select
ArrWorksheetNames = Arr
End Function
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Purpose: Creates a reference to the range spanning from the first row
' of a given range ('rg') to the row containing the bottom-most
' non-empty cell of the given range's columns.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Function RefColumns( _
ByVal rg As Range) _
As Range
If rg Is Nothing Then Exit Function
With rg.Rows(1)
Dim lCell As Range
Set lCell = .Resize(.Worksheet.Rows.Count - .Row + 1) _
.Find("*", , xlFormulas, , xlByRows, xlPrevious)
If lCell Is Nothing Then Exit Function ' empty range
Set RefColumns = .Resize(lCell.Row - .Row + 1)
End With
End Function
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Purpose: Returns the values of a range in a 2D one-based array.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Function GetRange( _
ByVal rg As Range) _
As Variant
If rg Is Nothing Then Exit Function
Dim rData As Variant
If rg.Rows.Count + rg.Columns.Count = 2 Then ' one cell only
ReDim rData(1 To 1, 1 To 1): rData(1, 1) = rg.Value
Else
rData = rg.Value
End If
GetRange = rData
End Function
' Irrelevant to the Question,
' but for a better understanding of `ArrWorksheetNames`.
Sub ArrWorksheetNamesTEST()
Const ExceptionsList As String = "Sheet1,Sheet2,Sheet3,Sheet4"
Const ListSeparator As String = ","
Const FirstIndex As Long = 4
Dim wb As Workbook: Set wb = ThisWorkbook
Dim wsNames As Variant
wsNames = ArrWorksheetNames(wb, ExceptionsList, ListSeparator, FirstIndex)
If IsEmpty(wsNames) Then
Debug.Print "No worksheets."
Else
Debug.Print "[" & LBound(wsNames) & "," & UBound(wsNames) & "]" _
& vbLf & Join(wsNames, vbLf)
End If
End Sub
关于excel - 将来自多个工作表的数据合并到一张关于列关键字的工作表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68583028/
我最近一直在学习 Clojure。 Clojure 世界中是否有类似 Scala 的工作表这样的东西,我可以在其中放入任何代码并在保存后立即对其进行评估?或者也许 Clojure 有类似的解决方案?
有人可以帮我吗?我想知道如何过滤工作表中的多个选项卡(C1-C19)。这是我所做的: 我创建了一张表格,将所有回复存储在我的谷歌表单(事件注册表单)中。每个参与者将收到一个坦克编号,每个坦克编号根据其
这就是我将打开的面板显示为 float 窗口的方式。 有人可以帮我将面板作为工作表运行吗?窗口对象是mWindow。我使用的许多标准代码都已被折旧。 NSOpenPanel *openPanel =
当您仅键入 worksheets() 时,默认范围 ActiveWorkbook 或 ThisWorkbook 是什么?对于那些不了解这些区别的人来说,它们非常重要,尤其是在 Excel 2013 中
我有一个带有一些图表的 HTML 页面。我想要做的是编写一个加载 javascript 函数,它将从 excel 表中读取值,将它们存储在变量中并在 html 页面上使用它们。我的问题是是否有任何 j
我需要将参数 callFrom 传递给 SwiftUI 中的工作表。 奇怪的是,该参数在第一次调用时没有使用,但对以下调用有效。 import SwiftUI struct ContentView:
我试着 var tempSheet = wrksheets[sheetName] as Worksheet; 在哪里 wrksheets是类型表 sheetName 是“带空格的工作表名称” 如果
该函数用作“ Assets 类别分配”引擎(在参数范围内具有约束)并在数组的每一行上模拟投资组合模型。我尝试使用四种方法将数组发布到工作表上,但每种方法都失败了。 对于 Assets A、B、C、D
目前,我的 excel 文件有两张表,一张名为“English”,一张名为“French”。 我以编程方式打开我的工作簿并编辑我的英文表,没有任何问题。当我打开第二张工作表时,出现以下错误: The
我添加了一个 VBA 表单 userform和一个模块 Module1在 Excel 中打开 Microsoft VBA 编辑器 (Alt+F11)。 现在,每当我打开任何其他 Excel 时,按 A
在单个 Excel 工作簿中,我想选择各种工作表来运行 VBA 子例程。我找到了显示如何遍历选定工作表的代码,它使用“MsgBox sh.Name”;但是,当我将代码放入其中时,它只会影响选择的最后一
我想知道是否有一个函数可以在 Excel 中加载特定于 Python 的工作表,例如,如果我有 34 张工作表只加载前 25 张工作表。通过以下行,我加载了所有工作表。 xlsx=pd.ExcelFi
我有一个名为“A”、“B”、“C”等的工作表的 xlsx。我需要形成一个名称为“A”、“B”、“C”的表作为第一列,以及来自的一些数据每个工作表中与第二列相同的单元格。例如,这可能看起来像: S
我有一张用密码保护的工作表。当我使用 VBA 更改该表上的任何内容时,我会像这样取消保护: Private Sub Worksheet_Change(ByVal target As Range)
我想将 Excel 文档插入 Excel 工作表。我可以通过以下步骤手动执行此操作; 插入/文本/对象/从文件创建(勾选显示为图标)/浏览。 然后我选择文件并插入文档。 我想通过宏来做到这一点。 (录
是否可以创建 批处理文件那将执行以下操作? 重命名 Excel 文件中的单个工作表(不是 Excel 工作簿/文件本身) 将简单格式应用于 Excel 文件 - 例如,将字体和字体大小应用于整个工作簿
Private Sub CommandButton1_Click() Dim ws As Worksheet With Application.FileDialog(msoFileDialog
我想知道是否可以在不复制该工作表的情况下引用另一本工作簿中的 Excel 工作表? 情况:我有一些非常大的工作表,其中充满了各种数据,但我不想在我的工作簿中保留它们的副本,因为虽然每个工作簿都使用相同
我有这个 Python 字典,我想将这个数据写入 Excel 文件。 注意:有很多类别,每个类别有很多汽车(为简单起见,我使用了 2 个类别) data = {"Category": {"Diesel
我有一个 excel 工作簿,在工作簿中我有 2 张名为 Front Page 和 Drafting 的工作表。起草工作表引用了首页工作表中的一些值。这只是一个基本的引用 我有像这样的公式:='Fro
我是一名优秀的程序员,十分优秀!