简体   繁体   中英

How can you write a VBA script to delete all cells in a range containing a certain string?

If I have a large range of cells, and I want to delete all cells containing just a "," or similar, how can I express this in code? I was thinking something along the lines of

If Range("C1:C100").Value = "," Then 
Active.Cell.Delete Shift:=xlRight 

I know this is terrible, but hopefully it gets my point across.

Thanks!

conceptually (not in front of Excel right now)

dim cel as range
for each cel in Range("C1:C100")
   if cel.Value = "," Then
      cel.Delete Shift:=xlRight 
   end if
next cel

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM