我有一个大约3,000行的工作表.其中一列包含种族数据,但它采用数字格式,而不是文本格式,例如:
我想在VBA中编写一个使用Select Case(或......?)的模块,将此列中的值从整数换成text.有人能告诉我如何实现这一目标吗?
下面是一个快速的VBA mashup,用替换代替你的Current Selection值:
Option Explicit
Option Base 1
Public Sub ReplaceData()
Dim RangeCells As Range
Dim LookupArray(4) As String, RangeCell As Range
LookupArray(1) = "Test A"
LookupArray(2) = "Test B"
LookupArray(3) = "Test C"
LookupArray(4) = "Test D"
For Each RangeCell In Selection
If IsNumeric(RangeCell.Value) And RangeCell.Value <= UBound(LookupArray) And RangeCell.Value >= LBound(LookupArray) Then
RangeCell.Value = LookupArray(Val(RangeCell.Value))
End If
Next RangeCell
End Sub
Run Code Online (Sandbox Code Playgroud)
假设:所有可能的单元格值都包含在数组索引中.否则,选择大小写可能就是您要切换到的大小写.如果您无法想出如何切换到那个,请告诉我.
希望这能解决你的问题.