代码不会插入列,直到找到范围内的所有列,当它到达第22列时停止,即使我有另外6列可用,如果我在这里指定了一个数字40代替NewColsone代码{{ 1}}它的工作原理
select distinct tname,
min(tscore) as min_score,
max(tscore) as max_score
from test_table
group by tname;
答案 0 :(得分:0)
尝试
coly = 6
While NewColsone > coly
Columns(Coly).Insert Shift:=xlToRight
NewColsone = .UsedRange.Columns.Count
coly = coly + 4
Wend
而不是
For coly = 6 To NewColsone Step 4 ' starting from 6th column enter a new column after consecutive 3 columns
NewColsone = .UsedRange.Columns.Count
Columns(coly).Insert Shift:=xlToRight
NewColsone = NewColsone + 1
Next coly