1.使用前請先備份資料
2.不支援重覆執行
Sub Filler()
Range("A65535").End(xlUp).Select
While True
ActiveCell.Offset(3, 0) = "流量"
If ActiveCell.Row > 4 Then
ActiveCell.Offset(-4, 0).Select
Else
Exit Sub
End If
Wend
End Sub
我不像海綿大大VBA那麼強,我只會用公式作業,
C1輸入1
C2輸入公式:
=IF(MOD(ROW(A2)-1,4)=0,OFFSET(C1,-3,0,1,1)+1,IF(MOD(ROW(A2),4)=0,"流量",""))
再向下複製到要求的列數。
練習一下有點生疏的golang。XD
package main
import (
"os"
"strconv"
xlsx "github.com/360EntSecGroup-Skylar/excelize/v2"
)
func main() {
var wb *xlsx.File
var err error
if fileExists("test.xlsx") {
wb, err = xlsx.OpenFile("test.xlsx")
if err != nil {
panic(err)
}
} else {
wb = xlsx.NewFile()
}
defer wb.SaveAs("test.xlsx")
if wb.GetSheetIndex("Sheet1") == -1 {
wb.NewSheet("Sheet1")
}
for i := 4; i < 3000; i += 4 {
wb.SetCellValue("Sheet1", "C"+strconv.Itoa(i), "流量")
}
}
func fileExists(filename string) bool {
info, err := os.Stat(filename)
if os.IsNotExist(err) {
return false
}
return !info.IsDir()
}