本帖最后由 wtujcf123 于 2023-5-25 18:06 编辑
使用gpt,让编写一个excel vba脚本,点击按纽实现在b列数值不为1时,在a列填写这个公式:IF(B3>1,TRIM(LEFT(SUBSTITUTE(A2&".",".","."&REPT(" ",50),B3-1),50)),)&-LOOKUP(,-INT(LEFT(0&TRIM(RIGHT(SUBSTITUTE("."&A2,".",REPT(" ",50),B3),50)),ROW($1:$16))))+1。
程序给出的代码是
- Sub ApplyFormula()
- Dim lastRow As Long
- lastRow = Cells(Rows.Count, "B").End(xlUp).Row
-
- For i = 3 To lastRow
- If Cells(i, "B").Value <> 1 Then
- Cells(i, "A").Formula = "=IF(B" & i & ">1,TRIM(LEFT(SUBSTITUTE(A" & i - 1 & "&""."",""."."&REPT("" "",50),B" & i & "-1),50)),)&-LOOKUP(,-INT(LEFT(0&TRIM(RIGHT(SUBSTITUTE(""."&A" & i - 1 & ",""."",REPT("" "",50),B" & i & "),50)),ROW($1:$16))))+1"
- End If
- Next i
- End Sub
复制代码 但其中的这个代码一直显示红色,无法运行。
- Cells(i, "A").Formula = "=IF(B" & i & ">1,TRIM(LEFT(SUBSTITUTE(A" & i - 1 & "&""."",""."."&REPT("" "",50),B" & i & "-1),50)),)&-LOOKUP(,-INT(LEFT(0&TRIM(RIGHT(SUBSTITUTE(""."&A" & i - 1 & ",""."",REPT("" "",50),B" & i & "),50)),ROW($1:$16))))+1"
复制代码
不知道该如何修改,麻烦各位老师帮忙修改下。
求助-自动填写公式.rar
(14.89 KB, 下载次数: 0)
|