我需要弄清楚如何告诉VBA转到当前行的M列中的单元格,并在满足条件时将数字格式更改为0.00。但是,当前行中的其他单元格必须保持0数字格式。以下是目前为止的代码:
Sheets("xxx").Activate
With Sheets("xxx")
For Lrow = 1 To .UsedRange.Rows.Count
With .Cells(Lrow, "J")
If Not IsError(.Value) Then
If .Value = "Desk to adjust" Then
Sheets("xxx").UsedRange.Rows(Lrow).Interior.ColorIndex = 36
Sheets("xxx").UsedRange.Rows(Lrow).NumberFormat = "0"
End If
If .Value = "Desk to adjust" Then
Sheets("xxx").Range("M" & ActiveCell.Row).Select.NumberFormat = "0.00"
End If
End If
End With
Next
End With我得到的错误是这样的,如果:
If .Value = "Desk to adjust" Then
Sheets("xxx").Range("M" & ActiveCell.Row).Select.NumberFormat = "0.00"
End If发布于 2015-10-08 13:59:44
因为我的评论中的注释起了作用(我认为还有更深层次的问题),所以我将把它作为一个答案,这样您就可以标记为已接受的问题,并结束这个问题:
你指的是ActiveCell.Row,当它不清楚活动细胞实际上是什么的时候。记住,活动单元要么是(1)在Excel中手动单击的单元格;要么是(2) VBA中有.Select写入的单元格。ie: Range("A1").Select - in通常不指活动单元格。在这里,试着只引用Lrow,而不是ActiveCell.Row。
https://stackoverflow.com/questions/33017608
复制相似问题