What does this macro do?
Formula:![]()
Please Login or Register to view this content.
What does this macro do?
Formula:![]()
Please Login or Register to view this content.
Nothing; it doesn't compile.
This toggles text wrapping in the active cell:
![]()
Please Login or Register to view this content.
Entia non sunt multiplicanda sine necessitate
You don't need the End If as shg points out.
Selection means one or more cells but if the selection is an object like a chart or a picture, then it would not execute since they are not a range of one or more cells.
I guess that wraptext should be obvious, it sets wraptext in the selection to opposite (NOT) the current state. Ergo, it toggles wraptext state.![]()
Please Login or Register to view this content.
Last edited by Kenneth Hobson; 01-15-2016 at 01:34 PM.
Hello zanshin777,
You could also try;
Regards.![]()
Please Login or Register to view this content.
Please consider:
Be polite. Thank those who have helped you. Then Click on the star icon in the lower left part of the contributor's post and add Reputation. Cleaning up when you're done. If you are satisfied with the help you have received, then Please do Mark your thread [SOLVED] .
Equivalent to pressing the Wrap Text button (Home tab, Alignment group)
It didn't declare "Range". Why?
ActiveCell="Range"
I don't understand what you mean.
If your selected Cell is say D4, then that is the "Range" you have selected. Or Cell D4 could also be referred to as the Target.Cell, or the ActiveCell.
That is why, "It didn't declare "Range" "
There range is used in "" so it is a string rather than variable.
But string is a value so it should not be changed rather than variables.
Am I right?
I think you are getting confused. ActiveCell is a Range. It is not "Range" which is a string. If you want to compare to a string, then TypeName() will convert it to a string value which may be "Range". Selection can be a range but it can be other things like Charts, Sheets, Shapes, etc. as well.
The code that Winon showed in post #4 is used in a sheet object. As such, there is not need to use TypeName() since a selection of a range means that a range was selected with is Selection or Target. So, i you want to automatically toggle the wraptext property for a selected range, then that is you best route. I fear that it might toggle when you don't want it to though.
ActiveCell is a range. I don't have any problem with it.
However here "Range" is a string. Isn't it?
If TypeName(Selection) = "Range" Then
But a string is a value so it should not be changed. But the range is dynamic. It changes along the spreadsheet depending where we select on the spreadsheet.
So It should not be a string (constant).
Thus I find it confusing.
Selection as I said "can be" a Range. TypeName(Selection) will then be "Range" only if the current selection is a range of one or more cells.
I guess you can set some variable to have the value of "Range" but I don't see that serving any purpose.
To use the code for the worksheet's Selection event, then right click your sheet's tab, View Code, and paste #4's code.
If you want more manual control, then assign Toggle to a hot-key combination. If just want to run it on one cell, then ActiveCell will work. If you want it to run on one or more cells, Selection should be used.
Last edited by Kenneth Hobson; 01-19-2016 at 10:26 AM.
Thank you very much sir.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks