我有两个工作表。一个是长期计划日历,顶部是日期,左侧是对象。另一个工作表是数据表。每个日历条目都是它自己的行,并且有一列具有另一个工作表的日历条目的单元格地址。我试图在日历工作表中添加评论,但是使用以下代码收到错误消息。关于我做错了什么的任何建议?谢谢!
import numpy
import matplotlib.pyplot
data_file = open("mnist_train_100.csv",'r')
data_list = data_file.readlines()
data_file.close()
答案 0 :(得分:0)
这可用于创建注释,然后将文本添加到注释中。如果偏移单元的值为空,则代码将错误输出。添加一些错误检查可以防止这种情况发生
Sub UpdateLTP()
Dim xlRange As Range
Dim xlCell As Range
Sheets("Long Term Plan").Select
Set xlRange = Range(Range("A1"), Range("A1").SpecialCells(xlLastCell))
xlRange.ClearComments
Sheets("Data").Select
Set xlRange = Range("AA2:AA" & Range("AA" & Rows.Count).End(xlUp).Row)
For Each xlCell In xlRange
If xlCell.Value <> "" Then
With Sheets("Long Term Plan").Range(xlCell.Value)
.AddComment
.Comment.Visible = False
.Comment.Text Text:=xlCell.Offset(0, -1).Value
End With
End If
Next xlCell
End Sub
此代码检查以确保偏移单元格不为空
Sub UpdateLTP()
Dim xlRange As Range
Dim xlCell As Range
Sheets("Long Term Plan").Select
Set xlRange = Range(Range("A1"), Range("A1").SpecialCells(xlLastCell))
xlRange.ClearComments
Sheets("Data").Select
Set xlRange = Range("AA2:AA" & Range("AA" & Rows.Count).End(xlUp).Row)
For Each xlCell In xlRange
If xlCell.Value <> "" Then
If xlCell.Offset(0, -1).Value <> "" Then
With Sheets("Long Term Plan").Range(xlCell.Value)
.AddComment
.Comment.Visible = False
.Comment.Text Text:=xlCell.Offset(0, -1).Value
End With
End If
End If
Next xlCell
End Sub
答案 1 :(得分:0)
请使用此代码。我希望你可以在没有解释的情况下解决,因为代码非常简单,差异将帮助你找出错误发生的位置。我已经测试了下面的代码,它运行正常。希望这会有所帮助。
Option Explicit
Sub UpdateLTP()
Dim xlCell, xlRange, SourceRange As Range
Dim rowCount As Integer
Set SourceRange = Sheets("Data").Range("AA2:AA" & Range("AA" & Rows.Count).End(xlUp).Row)
For Each xlCell In SourceRange
If xlCell.Value <> "" Then
If xlCell.Offset(0, -1).Value <> "" Then
With Sheets("Long Term Plan").Cells(xlCell.Row, xlCell.Column)
'' Clear Comments as needed from our source sheet.
.ClearComments
.AddComment (CStr(xlCell.Offset(0, -1).Value))
'' Please change to false as needed.
.Comment.Visible = True
End With
End If
End If
Next xlCell
End Sub