如果不包含值
我有一个宏,该宏可以从n = iCount的列开头的一系列列中创建数据。
例如,如果iCount = 4,则列为d,e,f,g。
在所有这些列中,如果单元格不包含“ [at]”,我希望清除单元素的内容。
最佳地,我还希望将所有剩余数据移到左侧,这意味着每行的数据在D列开始,没有差距,但这是次要的重要性。
我宏的前部。
Dim Treffer As Worksheet
Dim iCount As Long
Dim i As Long
Set Treffer = ActiveWorkbook.Worksheets("Treffer")
iCount = InputBox(Prompt:="How many columns should be created?")
For i = 1 To iCount
Treffer.Columns(5).EntireColumn.Insert
Treffer.Range("E1").Value = "Anmelder" & (iCount + 1) - i
Next i
Treffer.Range("D2:D" & Treffer.Cells(Rows.Count, "D").End(xlUp).Row).TextToColumns , _
Destination:=Treffer.Range("E2:E" & Treffer.Cells(Rows.Count, "N").End(xlUp).Row), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, _
Semicolon:=False, Comma:=False, Space:=False, Other:=True, OtherChar _
:="" & Chr(10) & "", FieldInfo:=Array(1, 1), TrailingMinusNumbers:=True
Treffer.Columns(4).EntireColumn.Delete
I have a macro that creates data in a range of columns starting from column D onwards with n=iCount.
e.g. if iCount=4, then the columns are D, E, F, G.
Throughout all these columns I would like to clear cell contents if the cell does not contain a "[AT]".
Optimally, I would also like all the leftover data to be moved to the left, meaning data for each row starts in column D and there are no gaps, but that is of secondary importance.
The prior parts of my macro.
Dim Treffer As Worksheet
Dim iCount As Long
Dim i As Long
Set Treffer = ActiveWorkbook.Worksheets("Treffer")
iCount = InputBox(Prompt:="How many columns should be created?")
For i = 1 To iCount
Treffer.Columns(5).EntireColumn.Insert
Treffer.Range("E1").Value = "Anmelder" & (iCount + 1) - i
Next i
Treffer.Range("D2:D" & Treffer.Cells(Rows.Count, "D").End(xlUp).Row).TextToColumns , _
Destination:=Treffer.Range("E2:E" & Treffer.Cells(Rows.Count, "N").End(xlUp).Row), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, _
Semicolon:=False, Comma:=False, Space:=False, Other:=True, OtherChar _
:="" & Chr(10) & "", FieldInfo:=Array(1, 1), TrailingMinusNumbers:=True
Treffer.Columns(4).EntireColumn.Delete
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
似乎您正在创建更多的工作,继续使用
texttocolumns
,并且使用split()
。尝试这样的事情:
Seems like you are creating more work continuing to use
TextToColumns
, and would be better off usingSplit()
.Try something like this: