Earlier today I got some help in developing a bit of code that would take the contents of a cell and place it in a comment that could display when being moused over.
It works great, but on a 6000 row spreadsheet it can take a while. I read here that you can potentially replace looping logic with array logic to speed up the process.
Any idea where I'd start in turning this from loop-based to array-based?
Dim iCell As Range
On Error Resume Next 'included because of an error when the .Formula function was triggered
For Each iCell In Selection
With iCell
If CStr(.Value) <> "" Then
.ClearComments
.AddComment
.Comment.Visible = False
.Comment.Text Text:=CStr(.Value)
.Comment.Shape.ScaleWidth 5.87, msoFalse, msoScaleFromTopLeft
.Comment.Shape.ScaleHeight 5.87, msoFalse, msoScaleFromTopLeft '2.26 was the original height
End If
If .Formula <> "" Then
.ClearComments
.AddComment
.Comment.Visible = False
.Comment.Text Text:=CStr(.Formula)
.Comment.Shape.ScaleWidth 5.87, msoFalse, msoScaleFromTopLeft
.Comment.Shape.ScaleHeight 5.87, msoFalse, msoScaleFromTopLeft
End If
End With
Next
End Sub
As with last time, any and all help is appreciated, be it guidance or examples or a solution - I intend to try and reverse engineer it to teach myself more about this stuff. Thanks!
Dim aMyArray As Variant,aMyArray = Selection.ValueThen loop throughaMyArray(r,c)with limits r =LBound(aMyArray,1)toUBound(aMyArray,1), c =LBound(aMyArray,2)toUBound(aMyArray,2). But based on your IF blocks, it won't work on Array. You can check blank cells withIsEmpty(iCell). You can useiCell.HasFormulato check if it's storing a formula or a value. You are at the moment gets only the formula.