gpt4 book ai didi

excel - 使特定列中的所有事件单元格为其绝对值

转载 作者:行者123 更新时间:2023-12-03 00:38:55 25 4
gpt4 key购买 nike

你能帮我改正我的 VBA 代码吗?我想将 U 列的值转换为绝对值,直到事件行为止,这意味着删除负数。
这是我的 VBA 代码:

Sub MakeColumnsAbsoluteValue()

Dim sht As Worksheet
Dim rngToAbs As Range
Dim LastRow As Long
Dim c As Range

Set sht = ThisWorkbook.Sheets("MJEBlackline")
LastRow = sht.Cells(sht.Rows, Count, "U").End(xlUp).Row
Set rngToAbs = Range("U5:U" & LastRow)

For Each c In rngToAbs
c.Value = Abs(c.Value)

Next c


End Sub

最佳答案

行问题 LastRow = sht.Cells(sht.Rows, Count, "U").End(xlUp).Row

使用,代替.并且不在rngToAbs中指定工作表引用

尝试:

Sub MakeColumnsAbsoluteValue()

Dim sht As Worksheet
Dim rngToAbs As Range
Dim LastRow As Long
Dim c As Range

Set sht = ThisWorkbook.Sheets("FF")
LastRow = sht.Cells(sht.Rows.count, "U").End(xlUp).row
Set rngToAbs = sht.Range("U5:U" & LastRow)

For Each c In rngToAbs
c.Value = Abs(c.Value)

Next c


End Sub

关于excel - 使特定列中的所有事件单元格为其绝对值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57585430/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com