VBA 将结尾的值更改为组合框值
VBA change value ending to combobox value
我正在尝试将值以“UZL”开头的单元格的“LanguageBox”组合框中的单元格值的最后 3 个符号替换。并以“.ENG”结尾。所有这一切都发生在 E 列 ("E2:E"&LastRow)。
有人可以分享这个代码吗?
工作簿示例:
https://easyupload.io/te2xll
试试,
Private Sub CommandButton1_Click()
Dim vDB As Variant
Dim rngDB As Range
Dim s As String, sReplace As String
Dim i As Long
Dim Ws As Worksheet
Set Ws = Sheets("BOM")
With Ws
Set rngDB = .Range("e2", .Range("e" & Rows.Count).End(xlUp))
End With
vDB = rngDB
For i = 1 To UBound(vDB, 1)
s = vDB(i, 1)
If s Like "UZL.*" And s Like "*.ENG" Then
sReplace = Me.LanguageBox.Value '"RUS"
s = Replace(s, "ENG", sReplace)
vDB(i, 1) = s
End If
Next i
rngDB = vDB
End Sub
假设您已经在用户表单中插入了一个命令按钮,当您在用户表单代码中单击命令按钮时插入它。它可以以不同的方式实现。
- 用户表单图片
- 用户表单代码图片
我正在尝试将值以“UZL”开头的单元格的“LanguageBox”组合框中的单元格值的最后 3 个符号替换。并以“.ENG”结尾。所有这一切都发生在 E 列 ("E2:E"&LastRow)。
有人可以分享这个代码吗?
工作簿示例: https://easyupload.io/te2xll
试试,
Private Sub CommandButton1_Click()
Dim vDB As Variant
Dim rngDB As Range
Dim s As String, sReplace As String
Dim i As Long
Dim Ws As Worksheet
Set Ws = Sheets("BOM")
With Ws
Set rngDB = .Range("e2", .Range("e" & Rows.Count).End(xlUp))
End With
vDB = rngDB
For i = 1 To UBound(vDB, 1)
s = vDB(i, 1)
If s Like "UZL.*" And s Like "*.ENG" Then
sReplace = Me.LanguageBox.Value '"RUS"
s = Replace(s, "ENG", sReplace)
vDB(i, 1) = s
End If
Next i
rngDB = vDB
End Sub
假设您已经在用户表单中插入了一个命令按钮,当您在用户表单代码中单击命令按钮时插入它。它可以以不同的方式实现。
- 用户表单图片
- 用户表单代码图片