Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从excel中删除列中已中断值的行_Excel_Vba - Fatal编程技术网

从excel中删除列中已中断值的行

从excel中删除列中已中断值的行,excel,vba,Excel,Vba,我的csv中有如下列: Id Name Price 1 Level X discontinued 34 3 Level Y Dicontinued 64 7 Level Z 94 Id Name Price 7 Leve

我的csv中有如下列:

Id            Name                     Price
1          Level X discontinued          34
3          Level Y Dicontinued           64
7          Level Z                       94
Id            Name                     Price
7          Level Z                       94
我想检查列名中的是中断的还是双继续的 如果是删除行,如果不是,则不执行任何操作,因此我的最终结果将是:

Id            Name                     Price
7          Level Z                       94

解决方案可以使用以下设置运行以下Excel宏
ExampleMacro
。此代码将过滤第一个工作表[此处
totalist
]复制第二个工作表中的内容[此处
过滤
]

Id            Name                     Price
7          Level Z                       94
注意:如果您希望更改名称,请使用我使用的相同名称或相应地更改以下宏的代码。否则它将无法工作

Id            Name                     Price
7          Level Z                       94
Sub ExampleMacro()

Dim i As Integer
Dim j As Integer
Set ShMaster = ThisWorkbook.Sheets("TotalList")
Set ShSlave = ThisWorkbook.Sheets("Filtered")

'cleanup for next macro executions
ShSlave.UsedRange.Clear

'copying the headers
ShSlave.Range("A1").Value = ShMaster.Range("A1").Value
ShSlave.Range("B1").Value = ShMaster.Range("B1").Value
ShSlave.Range("C1").Value = ShMaster.Range("C1").Value

'searching what to keep
j = 2
For i = 2 To ShMaster.UsedRange.Rows.Count
    'MsgBox "value is " & InStr(1, (Range("B" & i).Value), "discontinued")
    If InStr(1, (ShMaster.Range("B" & i).Value), "discontinued") = 0 Then
        While ShSlave.Range("C" & j).Value <> ""
            j = j + 1
        Wend
        ShSlave.Range("A" & j).Value = ShMaster.Range("A" & i).Value
        ShSlave.Range("B" & j).Value = ShMaster.Range("B" & i).Value
        ShSlave.Range("C" & j).Value = ShMaster.Range("C" & i).Value
    End If
Next i
End Sub
子示例宏()
作为整数的Dim i
作为整数的Dim j
Set ShMaster=ThisWorkbook.Sheets(“TotalList”)
Set ShSlave=ThisWorkbook.Sheets(“已筛选”)
'下一个宏执行的清理
ShSlave.UsedRange.Clear
'复制标题
ShSlave.Range(“A1”).Value=ShMaster.Range(“A1”).Value
ShSlave.Range(“B1”).Value=ShMaster.Range(“B1”).Value
ShSlave.Range(“C1”)值=ShMaster.Range(“C1”)值
“寻找要保留的内容
j=2
对于ShMaster.UsedRange.Rows.Count的i=2
“MsgBox”值为“&InStr(1,(范围(“B”和i).值),“已终止”)
如果仪表(1,(ShMaster.Range(“B”)和i.Value),“中断”)=0,则
而ShSlave.Range(“C”&j).Value“”
j=j+1
温德
ShSlave.Range(“A”&j).Value=ShMaster.Range(“A”&i).Value
ShSlave.Range(“B”&j).Value=ShMaster.Range(“B”&i).Value
ShSlave.Range(“C”&j).Value=ShMaster.Range(“C”&i).Value
如果结束
接下来我
端接头
希望这有帮助

Id            Name                     Price
7          Level Z                       94
祝你今天愉快,

Antonino

对名称应用筛选器,并删除带有“discon..”的行。到目前为止,您研究/尝试了哪些内容,您遇到了哪些具体问题?如果您能为解决您的问题付出一些努力,我们将不胜感激,请参阅@doki today我编辑了代码以修复可能出现的情况,在这种情况下,它的行为将不符合预期
Id            Name                     Price
7          Level Z                       94