我一整天都在研究这段代码,终于让一切都完美地工作了。唯一的问题是代码运行速度相当慢。考虑到它将用于具有数千行的工作簿,我想更改它。我对 vba 非常陌生,所以这里可能有一些东西是错误的或者看起来像是一个糟糕的快捷方式。我想我添加了一些可以加快速度的方法,但我不知道是否可以做其他事情。
Sub Degree_Workboook_Names_major1()
Application.ScreenUpdating = False
Application.DisplayStatusBar = False
Application.EnableEvents = False
'Inserts a new column after column H named department names
range("I1").EntireColumn.Insert
range("I1").Value = "DeptName"
Dim abbrRange As range 'range to hold the columns with the department names
Set abbrRange = range("H:H")
'Writes the department name in the the department name column next to the associated abbr
For Each cell In abbrRange
If cell.Value = "ACC" Then
cell.Activate
ActiveCell.Offset(0, 1).Activate
ActiveCell.Value = "Department of Accounting"
End If …Run Code Online (Sandbox Code Playgroud)