|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
本帖最后由 zxsea_7426 于 2022-12-7 07:38 编辑
这段代码是我写,还是我改
我发现楼主代码抄错了啊。我运行还报错了。
重新修改加如下:
Sub new_Click()
Dim rng As Range
Set d = CreateObject("scripting.dictionary")
ar = Sheet1.[a1].CurrentRegion.Resize(, 4)
For i = 2 To UBound(ar)
d(ar(i, 1)) = Array(ar(i, 3), ar(i, 4))
Next i
dou_col = WorksheetFunction.RoundUp(d.Count / 25, 0) '一行标题+25题分栏
ReDim arr(1 To 26, 1 To dou_col * 2)
With Sheet3
For j = 1 To UBound(arr, 2) Step 2
arr(1, j) = "题号": arr(1, j + 1) = "答案"
Next j
n = 1
col_ = 1
For i = 1 To d.Count
n = n + 1
If n > 26 Then
col_ = col_ + 1
n = 2
End If
If d.exists(i) Then
arr(n, 2 * (col_ - 1) + 1) = "第" & i & "题"
arr(n, 2 * (col_ - 1) + 2) = d(i)(1)
If d(i)(0) <> d(i)(1) Then
If rng Is Nothing Then
Set rng = .Cells(n + 5, 2 * (col_ + 4) + 2)
Else
Set rng = Union(rng, .Cells(n + 5, 2 * (col_ + 4) + 2))
End If
End If
End If
Next
'=================================输出位置更改下方三行修改为:下方三行:===========
' Sheet3.[a1].Resize(UBound(arr), UBound(arr, 2)) = arr
' Sheet3.[al].Resize(UBound(arr), UBound(arr, 2)).HorizontalAlignment = xlCenter
' Sheet3.[a1].Resize(UBound(arr), UBound(arr, 2)).VerticalAlignment = xlCenter
Sheet3.[k6].Resize(UBound(arr), UBound(arr, 2)) = arr
Sheet3.[k6].Resize(UBound(arr), UBound(arr, 2)).HorizontalAlignment = xlCenter
Sheet3.[k6].Resize(UBound(arr), UBound(arr, 2)).VerticalAlignment = xlCenter
'===============================================================================
If Not rng Is Nothing Then
rng.Font.Color = vbRed: rng.Font.Bold = True
End If
End With
End Sub
|
|