我在尝试使用宏时遇到问题。
如果在
final case class Person(name: String, age: Int)
object Person {
implicit val PersonFormat = Json.format[Person]
}
val jsonStr= """
{
"persons": [
{"name": "Foo", "age": 21},
{"name": "Bar", "age": 22},
{"name": "Baz", "age": 23}
]
}
"""
(Json.parse(jsonStr) \ "persons").as[List[Person]].map(p => p.name)
中发现某些值不匹配,但是我运行代码时,它错过了一些值,我想删除行。
到目前为止,这是我的代码:
((Json.parse(jsonStr) \ "persons") \\ "name").map(_.as[String])
非常感谢您
答案 0 :(得分:1)
删除行时必须向后循环,否则可能会跳过行。因此,您还必须在循环中切换到计数器。
Sub x()
Dim Codex As Range, i As Long
Set Codex = Worksheets("Centerlines Tracking").Range("D5", Range("D5").End(xlDown))
For i = Codex.Count To 1 Step -1
Select Case Codex.Cells(i)
Case "AD001", "AD002", "AD015", "AD031", "AD005", "AD035", "AD100", "AD107", "AD108", _
"AD152", "AD173", "CO017", "CO081", "CO102", "CO035", "CO169", "CR003"
'do nothing
Case Else
Codex.Cells(i).EntireRow.Delete
End Select
Next i
End Sub
答案 1 :(得分:0)
考虑使用此功能: https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/instr-function
加上精选案例说明:
testvalue = VBA.Trim(Cell.Value) '' use trim() to normalize the input
''debug.print(testvalue) ''enable this line to see what is happening in debug
Select Case True
Case instr(testvalue, "CR003", 1, vbTextCompare) ''use vbTextCompare to ignore caps/lower
''do stuff like delete or w/e
Case instr(testvalue, "CR004", 1, vbTextCompare)
Case Else
''do nothing or put a goto next: label
End Select