Consulting

Results 1 to 6 of 6

Thread: Need Help: Replace all Cells of a Column with its Caption, if Cells Value is "TRUE"

  1. #1

    Need Help: Replace all Cells of a Column with its Caption, if Cells Value is "TRUE"

    Hi!

    I'm really struggling by doing a VBA Code which checks each column individually if there are cell with the Value "TRUE". If so, the Caption (A1, B1, ...) should be inserted into the Cell.
    Like in the Attachment in the first Column every "True" was replaced by "Tageszeitanzeige".

    Can somebody help me?

    Thank you in advance!

    JulianCapture.jpg

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,747
    Location
    Try this


    Option Explicit
    
    Sub RepTrue()
        Dim c As Range
        
        On Error Resume Next
        For Each c In ActiveSheet.Cells(1, 1).CurrentRegion.EntireColumn.SpecialCells(xlCellTypeConstants, xlLogical).Cells
            If c Then c.Value = c.EntireColumn.Cells(1, 1).Value
        Next c
        For Each c In ActiveSheet.Cells(1, 1).CurrentRegion.EntireColumn.SpecialCells(xlCellTypeFormulas, xlLogical).Cells
            If c Then c.Value = c.EntireColumn.Cells(1, 1).Value
        Next c
        On Error GoTo 0
        
    End Sub
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  3. #3
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,132
    Location
    @ Julian_ki Hmmmm..... Can't say that the logic is clear here. Why would you want to replace all cell value with the caption if only one of the cell values in a column is true?

    Are you sure you didn't mean " for each cell in the column if its value is true, then replace that true value with the column caption?
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  4. #4
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,747
    Location
    I was assuming from the example that A2, A3, A6, etc. had been TRUE, and the column header A1 then replaced them
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  5. #5
    Hey!
    Paul assumed it right. The VBA is working perfect.

    Thank you!

    Cheers,
    Julian

  6. #6
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,132
    Location
    I'll mark it as Solved then.....
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

Posting Permissions

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