我需要以下帮助,
我有以下代码来查找A列中的数字。然后查看它是否从1到6,我将必须将其转换为test1 ... test6,如果1到6中的任何一个可用。
我的代码由于某种原因显示运行时错误和某些时候溢出错误。想知道是否有人可以帮我解决这个错误。提前谢谢!
Sub macro()
Dim rownum As Long, colnum As Long, currcell As Range
rownum = ActiveCell.Row
colnum = ActiveCell.Column
Sheets("Sheet1").Select
'Converting 1-6 into Test1-Test6
Do
Set currcell = ActiveSheet.Cells(rownum, 1)
If IsNumeric(currcell.Value) Then
If currcell.Value = 1 Then
currcell = "test1"
ElseIf currcell.Value = 2 Then
currcell = "test2"
ElseIf currcell.Value = 3 Then
currcell = "test3"
ElseIf currcell.Value = 4 Then
currcell = "test4"
ElseIf currcell.Value = 5 Then
currcell = "test5"
ElseIf currcell.Value = 6 Then
currcell = "test6"
Exit Do
End If
End If
rownum = rownum + 1
Loop
End Sub
答案 0 :(得分:2)
@SiddharthRout,我意识到DIM,这是一个错字......我不认为我可以使用.find因为我需要将更改修复为只有A列。 - user1204868 1分钟前
这是你在尝试的吗?
Option Explicit
Sub Sample()
Dim i As Long
With Sheets("Sheet1").Columns(1) '<~~ Col A
For i = 1 To 6
.Replace What:=i, Replacement:="test" & i, LookAt:=xlWhole, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
DoEvents
Next
End With
End Sub