【发布时间】:2020-08-22 03:40:57
【问题描述】:
我的两个变量 PackageOptions 和 cell.Value 具有相同的文本但不同的值。是否有一种方法可以格式化它们以匹配以便代码跳转到 if 语句?我尝试使用 Trim$ 和 ascii 格式,但不明白如何格式化。
字符串一是PackageOptions类型 字符串二是 PackageOptions 类型
从列表框中提取变量:
Dim PackageOptions
Dim Customer As String
Dim PreferredDate As String
Dim ServicesLine1 As String
Dim PackageOptions As String
Dim GoogleR As Byte
Dim InvoiceR As Byte
For i = 0 To LbCustomer.ListCount - 1
If LbCustomer.Selected(i) Then
Customer = Customer & LbCustomer.List(i) & vbNewLine
PreferredDate = PreferredDate & LbCustomer.List(i, 1) & vbNewLine
ServicesLine1 = ServicesLine1 & LbCustomer.List(i, 2) & vbNewLine
**PackageOptions** = PackageOptions & LbCustomer.List(i, 3) & vbNewLine
GoogleR = GoogleR & LbCustomer.List(i, 4) & vbNewLine '
InvoiceR = InvoiceR & LbCustomer.List(i, 5) & vbNewLine
End If
Next i
Dim PrRange As Range
Dim cell As RangeSet PrRange = shPrice.Range("PricingTable[Item]")
Dim ItemRange As Range
Set ItemRange = shPrice.Range("PricingTable[Item Number]")
>looping through a table column, return the row and item number of match
>the variables have different values (shown in images attached)
For Each cell In PrRange
If PackageOptions = cell.Value Then
ItemR = cell.Row - shPrice.Range("PricingTable[[#Headers],[Item]]").Row
ItemNumber = shPrice.Range("PricingTable[Item Number]").Cells(ItemR, 1).Value
End If
Next cell
【问题讨论】:
标签: vba string if-statement