|
本帖最后由 网海遨游 于 2019-10-11 15:06 编辑
把代码帮你注释下,你就明白怎么更改了。
Sub t20191011()
Dim sh As Worksheet, ar, j%, i%, n% '定义变量类型
Set sh = Sheets("sheet1") '定义工作表对象(这里工作表名叫Sheet1)
sh.[cc2:df60000].ClearContents '清除要写入数据的区域
ar = [{63,67,71,72,73,75,76,77,79}] 'Bk、BO、BS、BT、BU……对应的列号(即字母换成了数字)
For j = 7 To 377 Step 10 '从第7行循环到第377行,步进为10(即7、17、27、37……377)
If sh.Cells(j, 37).Value = "A" Then '如果AK列(转化成数字就37列)的值是A,就……
For Each i In ar '遍历相应的列(即遍历Bk、BO、BS、BT、BU……等列)
n = n + 1'累加、计数
If sh.Cells(j, i).Value = sh.Cells(384, i).Value Then sh.Cells(j, 80 + (3 * n - 2)) = 1 '如果等于该列的384行(最小值),相应的单元格值为1
If sh.Cells(j, i).Value = sh.Cells(385, i).Value Then sh.Cells(j, 80 + (3 * n - 1)) = 1
If sh.Cells(j, i).Value > sh.Cells(384, i).Value And sh.Cells(j, i).Value < sh.Cells(385, i).Value Then sh.Cells(j, 80 + 3 * n) = 1
Next i
n = 0 '初始化n=0(对Bk、BO、BS、BT、BU……每一列都要重新计数),不然在写入数据时会出错。
End If
Next j
End Sub
|
|