+ Reply to Thread
Results 1 to 15 of 15

A Macro Which Toggle A Boolean Property

  1. #1
    Forum Contributor
    Join Date
    01-16-2015
    Location
    Istanbul
    MS-Off Ver
    Office 365
    Posts
    928

    A Macro Which Toggle A Boolean Property

    What does this macro do?

    Formula: copy to clipboard
    Please Login or Register  to view this content.

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: A Macro Which Toggle A Boolean Property

    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

  3. #3
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: A Macro Which Toggle A Boolean Property

    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.
    Please Login or Register  to view this content.
    I guess that wraptext should be obvious, it sets wraptext in the selection to opposite (NOT) the current state. Ergo, it toggles wraptext state.
    Last edited by Kenneth Hobson; 01-15-2016 at 01:34 PM.

  4. #4
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: A Macro Which Toggle A Boolean Property

    Hello zanshin777,

    You could also try;

    Please Login or Register  to view this content.
    Regards.
    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] .

  5. #5
    Forum Contributor
    Join Date
    01-16-2015
    Location
    Istanbul
    MS-Off Ver
    Office 365
    Posts
    928

    Re: A Macro Which Toggle A Boolean Property

    Quote Originally Posted by shg View Post
    This toggles text wrapping in the active cell:
    What does that mean?

  6. #6
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: A Macro Which Toggle A Boolean Property

    Equivalent to pressing the Wrap Text button (Home tab, Alignment group)

  7. #7
    Forum Contributor
    Join Date
    01-16-2015
    Location
    Istanbul
    MS-Off Ver
    Office 365
    Posts
    928

    Re: A Macro Which Toggle A Boolean Property

    It didn't declare "Range". Why?

  8. #8
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: A Macro Which Toggle A Boolean Property

    ActiveCell="Range"

  9. #9
    Forum Contributor
    Join Date
    01-16-2015
    Location
    Istanbul
    MS-Off Ver
    Office 365
    Posts
    928

    Re: A Macro Which Toggle A Boolean Property

    I don't understand what you mean.

  10. #10
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: A Macro Which Toggle A Boolean Property

    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" "

  11. #11
    Forum Contributor
    Join Date
    01-16-2015
    Location
    Istanbul
    MS-Off Ver
    Office 365
    Posts
    928

    Re: A Macro Which Toggle A Boolean Property

    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?

  12. #12
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: A Macro Which Toggle A Boolean Property

    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.

  13. #13
    Forum Contributor
    Join Date
    01-16-2015
    Location
    Istanbul
    MS-Off Ver
    Office 365
    Posts
    928

    Re: A Macro Which Toggle A Boolean Property

    Quote Originally Posted by Kenneth Hobson View Post
    ActiveCell is a Range. It is not "Range" which is a string.
    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.

  14. #14
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: A Macro Which Toggle A Boolean Property

    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.

  15. #15
    Forum Contributor
    Join Date
    01-16-2015
    Location
    Istanbul
    MS-Off Ver
    Office 365
    Posts
    928

    Re: A Macro Which Toggle A Boolean Property

    Thank you very much sir.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Single command to toggle a Boolean?
    By Ed in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-20-2020, 12:43 AM
  2. macro for 14 boolean variables
    By flipper687 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-16-2014, 08:22 AM
  3. Problem Defining Toggle Buttion Value Property as a Variable
    By mandora in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-16-2014, 02:12 AM
  4. Macro To Copy Row Based On Boolean?
    By ViralSynergy in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 03-28-2012, 07:04 PM
  5. Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean) problem
    By 2funny4words in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-29-2009, 07:28 PM
  6. how to toggle the 'visible' property of a series
    By arioti in forum Excel Charting & Pivots
    Replies: 2
    Last Post: 10-08-2007, 10:05 AM
  7. how can I insert a macro into a boolean statement
    By Garrett in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 12-29-2005, 11:50 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1