我试图弄清楚如何将 Sub 的第一部分(对标题列表中的列进行操作)应用于其他类型的操作(原始设置为删除列表中的列)。
我的尝试几乎奏效了,它对列表应用了一些简单的格式:“RespID,Score”
但 Sub 仅适用于列表“RespID”中的第一项
我在 Sub 中唯一改变的是在底部之后的二分之二'~~> Act on columns
谢谢
Sub FormatRespIDScore360()
Dim WS As Worksheet
Dim ColList As String, ColArray() As String
Dim lastCol As Long, i As Long, j As Long
Dim boolFound As Boolean
Dim delCols As Range
Dim lastRow As Long
On Error GoTo Whoa
Application.ScreenUpdating = False
Set WS = Sheets("360")
ColList = "RespID, Score"
ColArray = Split(ColList, ",")
'~~> Get the last column
lastCol = WS.Cells.Find(What:=" ", After:=WS.Range("A1"), LookAt:=xlPart, _
LookIn:=xlFormulas, SearchOrder:=xlByColumns, SearchDirection:=xlPrevious, _
MatchCase:=False).Column
For i = 1 To lastCol
boolFound = False
'~~> Checking of the current cell value is present in the array
For j = LBound(ColArray) To UBound(ColArray)
If UCase(Trim(WS.Cells(1, i).Value)) = UCase(Trim(ColArray(j))) Then
'~~> Match Found
boolFound = True
Exit For
End If
Next
'~~> If not match not found
If boolFound = True Then
If delCols Is Nothing Then
Set delCols = WS.Columns(i)
Else
Set delCols = Union(delCols, WS.Columns(i))
End If
End If
Next i
'~~> Act on columns
If Not delCols Is Nothing Then
With Sheets(1)
lastRow = .Cells(.Rows.Count, delCols.Column).End(xlUp).Row
End With
With Sheets(1).Range(delCols, WS.Cells(lastRow, delCols.Column))
.NumberFormat = "0"
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
End If
LetsContinue:
Application.ScreenUpdating = True
Exit Sub
Whoa:
MsgBox Err.Description
Resume LetsContinue
End Sub