m2oTech.com

  • Increase font size
  • Default font size
  • Decrease font size
m2oTech.com

A macro to un-mess Excel comments

Print PDF

Ever experienced having tens of comments in Excel and finding they are all over the place (e.g. because you resized/added/removed cells)? I was quite sure there must be a better way and someone already did a macro to "fix" this... so here it is, I found this originally posted at this blog and allowed myself to copy and paste it (if you are the author and you want credits please let me know!).

All you need to do is:

  1. Add a macro to your spreadsheet (not "record a macro")
  2. In the VBA editor that opens paste the following code
  3. Optionally create a shortcut to the macro so that you can invoke it easily (else can run it from menu when needed)

This macro will place all of your comments back to where they belong (next to the cell they refer to).

Note: If you are trying to find a way to move comments on the sheet where you would like them to be... that's a different story. It does not seem to be possible!

Sub CommentFix()

' This macro modifies all comments in all open workbooks to:
' (1) move and size with cells
' (2) be physically positioned near the cell to which they correspond
' (3) be optimally sized appropriate to the text within
' This macro was created by combining code posted on the following website:
' http://www.contextures.com/xlcomments03.html

Dim thisfile As Workbook
Set thisfile = ActiveWorkbook
Dim MyWorkbook As Workbook
Dim MySheet As Worksheet
Dim MyComment As Comment
Dim CommentCount As Long
Dim lArea As Long
Dim fixed As Boolean
fixed = False
On Error GoTo NeedToUnprotect
For Each MyWorkbook In Workbooks
MyWorkbook.Activate
For Each MySheet In MyWorkbook.Sheets
MySheet.Activate
CommentCount = 0
For Each MyComment In MySheet.Comments
With MyComment.Shape
.Placement = xlMoveAndSize
.Top = MyComment.Parent.Top + 5
.Left = MyComment.Parent.Offset(0, 1).Left + 5
.TextFrame.Characters.Font.Name = "Tahoma"
.TextFrame.Characters.Font.Size = 8
.TextFrame.AutoSize = True
CommentCount = CommentCount + 1
End With
If MyComment.Shape.Width > 300 Then
lArea = MyComment.Shape.Width * MyComment.Shape.Height
MyComment.Shape.Width = 200
MyComment.Shape.Height = (lArea / 200) * 1.1
End If
Next MyComment
If CommentCount > 0 Then
MsgBox ("A total of " & CommentCount & " comments in worksheet '" & MySheet.Name & "' of workbook '" & MyWorkbook.Name & "'" & Chr(13) & "were repositioned and resized.")
fixed = True
End If
Next MySheet
Next MyWorkbook
thisfile.Activate
If fixed = False Then
MsgBox ("No comments were detected.")
End If
On Error GoTo 0
Exit Sub

NeedToUnprotect:
MsgBox ("You must unprotect all worksheets before running the macro.")
thisfile.Activate
Exit Sub

End Sub

 

 

BCD - A different kind of binaries

Print PDF

Decimal "08" gets coded in binary as "0000 1000", that's because the hexadecimal representation of the number is also "08".

but

Decimal "39" does not get coded as "0011 1001", because its hexadecimal representation is "27" (thus binary "0010 0111").

There is however a coding system called BCD (Binary Coded Decimal) which would code "39" exactly as "0011 1001". In other words BCD does with decimals what you'd normally do with hexadecimals, i.e. take each digit and "translate" it to a half-a-byte (a nibble) binary number. As only values from 0 to 9 can be represented by a decimal digit, only binary values from 0000 to 1001 can be "translated" (1010 to 1111 remain unused).

While this is mostly a relict of "old times" there are still areas where BCD is used. A good example are digital clocks, since some chips translate directly binary digits into 0-9 digits, without having to worry about characters like A-F, which would be present if translating to hexadecimals. Or, and that is how I learned about the existence of BCD, in some digital controls for lighting devices (DALI standard).

This topic on Wikipedia.

 

Pipelining in LabVIEW

Print PDF

A very simple concept to improve execution performance in LabVIEW. I found this on National Instruments website, while looking for information on how to handle threads in LabVIEW.

(image source: ni.com)

If A and B are two parts of the same process (calculation, ...) to be executed in a loop, we can execute half of it (A) in this iteration and the rest (B) in the next iteration. With only one more iteration (or maybe two?) we offer the compiler a chance to split the load on two CPUs, if available (that will be done by LV automatically).

 

Why I don't like multiprocess browsers

Print PDF

Ok, what does that title mean? I am talking about what Google Chrome and recent versions of Internet Explorer do, namely they treat each tab as a separate process from the OS point of view. Instead of launching one big process that contains all the tabs we currently have open in our browser, they launch a new process for each tab. This has the great advantage that crashing a tab does not mean crashing the entire browser. And that is in my opinion a good thing, but not a definite advantage in usability.

Now, how often does a webpage cause the browser to crash? Fairly often, but not that often. And how often do I need to open a new tab? Very often. The thing is, with overloaded or not so fast PCs (Win 7 could contribute here...) it takes some time to launch a new process. This does not mean minutes and even not seconds, but that fraction of a second (ok, saying one second is not a stretch) that makes you forget what you were going to do with your new tab (google something most likely).

Last but not least, closing a browser with 10 tabs open (that's often an underestimation) means shutting down 10 application, from the OS point of view. That will not take minutes, but several seconds is a good estimate, even on fast machines. Firefox with "show previous session" option enabled loads and "unloads" ten tabs in a matter of seconds (not many) especially when it's run on something else than Windows (e.g. Linux...)

 

Feature Phones Crashed by SMS Virus

Print PDF

What is a "feature phone" anyway? It is, as I've learned, a "normal cellphone", i.e. not a smartphone. One of those "old" phones 80% of worldwide mobile phones users (including myself) rely on. It turns out these old phones can be crashed quite easily by a malicious SMS through "special binary characters and overflowed headers" according to this article.

The process is aided by the network carrier repeating the sending operation when this fails, and by a special shutdown watchdog which is built in in some older Nokia phones, which shuts down the phone after receiving three malformed SMSes in a row.

What's not so bad in all this, is that the effects are only temporary, as the phone will work fine after restarting.

 
  • «
  •  Start 
  •  Prev 
  •  1 
  •  2 
  •  3 
  •  4 
  •  Next 
  •  End 
  • »


Page 1 of 4