# Excel中将数据替换为固定字符串

Sub 替换()

Set sourceSht = ThisWorkbook.Sheets("sheet1")
Dim hang, lie As Integer
Dim str1, str2, str3, str4, str5, str6, str7, str8, str9 As String
str1 = "[0 - 100]"
str2 = "[100 - 200]"
str3 = "[200 - 300]"
str4 = "[300 - 400]"
str5 = "[400 - 500]]"
str6 = "[500 - 600"
str7 = "[600 - 700]"
str8 = "[700 - 800]"
str9 = "[800 - 900]"
str10 = "[900 - 1000]"

'k = sourceSht.[a65535].End(xlUp).Row
hang = Sheets("sheet1").[a65535].End(xlUp).Row
'lie = Sheets("sheet1").[BF1].End(xlToLeft).Column

For m = 4 To hang Step 1

For n = 65 To 65 Step 1

s = Cells(m, n).Value
If 0 <= s And s < 100 Then
Cells(m, n).Value = str1

ElseIf 100 <= s And s < 200 Then
Cells(m, n).Value = str2

ElseIf 200 <= s And s < 300 Then
Cells(m, n).Value = str3

ElseIf 300 <= s And s < 400 Then
Cells(m, n).Value = str4

ElseIf 400 <= s And s < 500 Then
Cells(m, n).Value = str5

ElseIf 500 <= s And s < 600 Then
Cells(m, n).Value = str6

ElseIf 600 <= s And s < 700 Then
Cells(m, n).Value = str7

ElseIf 700 <= s And s < 800 Then
Cells(m, n).Value = str8

ElseIf 800 <= s And s < 900 Then
Cells(m, n).Value = str9

ElseIf 900 <= s And s <= 1000 Then
Cells(m, n).Value = str10
End If
Next
Next

End Sub

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客