- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用具有 11 个工作表的 EXCEL 文件,在此配置中:
VOL_CODE = 我要查找的代码。如果存在于工作表中,则应删除包含 VOL_CODE 的整行。
工作表:
Private Sub CommandButton3_Click()
'--- Remove VOL_CODE line from all worksheets -----
Dim ws1, ws2 As Worksheet
Dim VOL_CODE As String
Dim PLA, LIN As Integer
Set ws1 = Worksheets("NEW VOL DATA") '--- This is the Working Worksheet -----
VOL_CODE = “RS_123456” ‘--- This is the code to search for -----
For PLA = 1 To 10
If UCase(Range("K" & PLA)) <> "X" Then GoTo JUMP_PLA:
Set ws2 = Worksheets("DESTINATION" & Trim(Str(PLA)))
Do While True
On Error GoTo JUMP_PLA:
LIN = Application.WorksheetFunction.Match(VOL_CODE, ws2.Range("B:B"), 0)
ws2.Cells(LIN, 1).EntireRow.Delete
Loop
JUMP_PLA:
Next PLA
End Sub
问题是,当我执行代码时,它在
DESTINATION1 工作表中运行良好,包含或不包含 VOL_CODE(如果包含,它会循环删除 VOL_CODE 的行,直到不再有),然后,当找不到更多 VOL_CODE 条目时,它转到“JUMP_PLA:”和“下一个 PLA”...从那里重新开始,现在转到下一个“
DESTINATIONx ”工作表(下一个选择)...并且出现错误(找到或不是有效条目)当 Application.WorksheetFunction.Match 命令执行时:
最佳答案
Application.WorksheetFunction.Match 删除行
doDest
最好复制到标准模块(例如 Module1
)中,然后在您的按钮代码中调用:Private Sub CommandButton3_Click()
doDest
End Sub
Match
用于删除行。 NEW VOL DATA
。在它的 K1:K10
范围内,在几个单元格中输入一个 x
就可以了。 Option Explicit
Sub doDest()
'--- Remove VOL_CODE line from all worksheets -----
' Speed up the code (you won't see what the macro is doing).
Application.ScreenUpdating = False
Dim ws1 As Worksheet, ws2 As Worksheet 'Dim ws1, ws2 As Worksheet
Dim VOL_CODE As String
Dim PLA As Long, LIN As Long ' Dim PLA, LIN As Integer
Dim wb As Workbook: Set wb = ThisWorkbook ' The workbook with this code.
Set ws1 = wb.Worksheets("NEW VOL DATA") 'Set ws1 = Worksheets("NEW VOL DATA") '--- This is the Working Worksheet -----
VOL_CODE = "RS_123456" '--- This is the code to search for -----
For PLA = 1 To 10
'If StrComp(ws1.Range("K" & PLA).Value, "X", vbTextCompare) <> 0 _
Then GoTo JUMP_PLA
If UCase(ws1.Range("K" & PLA).Value) <> "X" Then GoTo JUMP_PLA ' If UCase(Range("K" & PLA)) <> "X" Then GoTo JUMP_PLA:
Set ws2 = wb.Worksheets("DESTINATION" & PLA) ' Set ws2 = Worksheets("DESTINATION" & Trim(Str(PLA)))
Do ' Do While True
' On Error GoTo JUMP_PLA:
' LIN = Application.WorksheetFunction.Match(VOL_CODE, ws2.Range("B:B"), 0)
' ws2.Cells(LIN, 1).EntireRow.Delete
On Error Resume Next ' Turn ON error trapping.
' "ws2.Columns("B")" is just an option, you can stick with
' "ws2.Range("B:B")".
LIN = Application.WorksheetFunction _
.Match(VOL_CODE, ws2.Columns("B"), 0)
If Err.Number <> 0 Then
On Error GoTo 0 ' Turn OFF error trapping.
'Debug.Print "Done with worksheet '" & ws2.Name & "'."
Exit Do ' or: GoTo JUMP_PLA
Else
On Error GoTo 0 ' Turn OFF error trapping.
ws2.Cells(LIN, 1).EntireRow.Delete
End If
Loop
JUMP_PLA:
Next PLA
Application.ScreenUpdating = True
MsgBox "Deleted rows containing '" & VOL_CODE & "'.", _
vbInformation, "Success"
End Sub
' Deletes all sheets named "DESTINATIONx", where x is from 1 to 10.
Sub deleteDest()
Dim wb As Workbook: Set wb = ThisWorkbook
Dim i As Long
For i = 1 To 10
Application.DisplayAlerts = False ' To prevent Excel from 'complaining'.
On Error Resume Next ' If a sheet does not exist.
wb.Sheets("DESTINATION" & i).Delete
On Error GoTo 0
Application.DisplayAlerts = True
Next i
End Sub
' Adds worksheets named "DESTINATIONx", where x is from 1 to 10.
' In each of those worksheets, adds "RS_123456" to up to 100 cells
' in 'random' rows from 1 to 1000 in column 'B'.
Sub createDest()
' Speed up the code (you won't see what the macro is doing).
Application.ScreenUpdating = False
Dim wb As Workbook: Set wb = ThisWorkbook
Dim ws As Worksheet, i As Long, j As Long, CurrName As String
For i = 1 To 10
CurrName = "DESTINATION" & i
On Error Resume Next ' Turn ON error trapping.
Set ws = wb.Worksheets(CurrName)
If Err.Number <> 0 Then
' Sheet with current name does not exist.
Set ws = wb.Worksheets _
.Add(After:=wb.Worksheets(wb.Worksheets.Count))
ws.Name = CurrName
'Else ' Sheet with current name exists.
End If
On Error GoTo 0 ' Turn OFF error trapping.
ws.Columns("B").Clear ' Ensures new data if sheets already exist.
For j = 1 To 100
ws.Cells(Application.WorksheetFunction.RandBetween(1, 1000), "B") _
.Value = "RS_123456"
Next j
Next i
wb.Sheets(1).Select
Application.ScreenUpdating = True
End Sub
' Counts the number of cells in column 'B' containing a value.
Sub countDest()
Dim wb As Workbook: Set wb = ThisWorkbook
Dim i As Long
For i = 1 To 10
On Error Resume Next
Debug.Print "DESTINATION" & i, wb.Worksheets("DESTINATION" & i) _
.Columns("B") _
.SpecialCells(xlCellTypeConstants) _
.Cells.Count
If Err.Number <> 0 Then
Debug.Print "DESTINATION" & i, "No cells found."
End If
Next i
End Sub
' Ultimate test
Sub testDest()
deleteDest ' Deletes the sheets.
createDest ' Creates the worksheets with random data.
countDest ' Counts the cells containing "RS_123456" (Debug.Print).
doDest ' Deletes the rows containing "RS_123456" in column 'B'.
countDest ' Counts the cells containing "RS_123456" (Debug.Print).
MsgBox "Ultimate: deleted, created, counted, done and counted again."
End Sub
' Initialize
Sub initCreateAndCount()
deleteDest ' Deletes the sheets.
createDest ' Creates the worksheets with random data.
countDest ' Counts the cells containing "RS_123456" (Debug.Print).
MsgBox "Initialized: Sheets deleted and created, and cells counted."
End Sub
' Shows how even when the 'dest' sheets exist, new values are generated.
Sub testCreateCount()
createDest ' Creates the worksheets with random data.
countDest ' Counts the cells containing "RS_123456" (Debug.Print).
MsgBox "Sheets created and cells counted."
End Sub
关于excel - Application.WorksheetFunction.Match 没有按预期工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63662687/
我正在尝试为匹配中的每个匹配呈现一些 HTML,但是,我不太确定 实际上是正确的。 更具体地说,我不确定我是否可以使用 v-bind:match='match'在与循环相同的元素上 v-for='ma
它具有看似简单的代码: method match(Any:U: |) { self.Str; nqp::getlexcaller('$/') = Nil } 但是,这是它的行为: (^3).matc
如果您想检查某项是否与正则表达式匹配,如果是,请打印第一组,您就可以了.. import re match = re.match("(\d+)g", "123g") if match is not N
以下两个查询的结果有差异吗? SELECT * FROM table1, table2 WHERE ( MATCH(table1.row1) AGAINST('searchstring' IN
我正在尝试为我的日志文件创建一个语法文件。它们采用以下格式: [time] LEVEL filepath:line - message 我的语法文件如下所示: :syn region logTime
String#match 和 Regexp#match 在匹配成功时返回一个 MatchData: "".match(//) # => # //.match("") # => # //.match(:
我的代码中有这个函数: func match(match: GKMatch, player playerID: String, didChangeState state: GKPlayerConnec
我对 match 和 case 之间的区别感到困惑。在 document ,其中提到match支持通用模式匹配。 > (define (m x) (match x [(list a
我在检查特定元素中的空 HTML 内容时遇到了问题。当我使用 someElement.trim().match("") 即使 HTML 内容为空,我有时也会得到 true。我改成了 someEleme
我正在尝试使用正则表达式查找包含特定词的两个词之间的所有内容,但是这些词是重复的,所以我没有得到我想要的匹配项。 例如,我想要“你好”和“再见”之间的所有内容,以便它们之间存在“苹果”一词: hell
我目前正在构建一个 PHP 脚本,它将在需要时响应 HTTP“304 Not Modified”。 (请参阅 question #2086712 了解我目前所做的事情)。 目前我回答以下问题: If-
给定以下 XML 10 我希望能够正确识别内部 的 s : result = subject.gsub(/]*>)/, '<') 解释: ]* # any number of charact
这个问题在这里已经有了答案: How to error handle 1004 Error with WorksheetFunction.VLookup? (3 个回答) 3年前关闭。 目标:查找输入
我已经尝试了好一阵子了,但是我似乎无法弄清楚这两者之间的区别。特别是,与数据数组有关的差异: PS C:>$myarray = "a", "ab", "abc" PS C:>$myarray -mat
我正在努力研究如何构建一个宏,让我可以将模式和结果以向量的形式传递给 core.match/match 。我希望能够做到这一点: (let [x {:a 1} patterns [[{:a
这个问题在这里已经有了答案: Reference - What does this regex mean? (1 个回答) 关闭 8 年前。 如果这看起来微不足道但只是为了理解正则表达式,请原谅我:
我的 MySQL 表中有大约 20 行,其 Title 列为 Elsewhere 并具有其他不同的列参数。 我目前正在使用这样的查询,因为我的大多数搜索(通过 PHP 文件)都需要我进行猜测。所以我使
当找到匹配时,我必须从字符串中删除单词 让我们看看 我的输入字符串是 “肯诺克斯路” 比赛表演中的单词表 街道 驾驶 道路 4. 车道 输出字符串应该是: KENOX 我正在使用 vb.net 作为此
我正在搜索以下形式的字符串模式: XXXAXXX # exactly 3 Xs, followed by a non-X, followed by 3Xs 所有的 X 必须是相同的字符,并且 A 不能
好吧,我是 gulp 和 sass 的新手,我正在努力让它发挥作用。我正确安装了所有东西,但我收到了这个愚蠢的错误。有解决办法吗? PS C:\Users\Bojan Kolano\Desktop\F
我是一名优秀的程序员,十分优秀!