View Full Version : [SOLVED:] Need Help: Replace all Cells of a Column with its Caption, if Cells Value is "TRUE"
julian_ki
11-14-2016, 09:48 AM
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!
Julian17592
Paul_Hossler
11-14-2016, 10:16 AM
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
Aussiebear
11-14-2016, 10:52 PM
@ 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?
Paul_Hossler
11-16-2016, 06:41 AM
I was assuming from the example that A2, A3, A6, etc. had been TRUE, and the column header A1 then replaced them
julian_ki
11-17-2016, 12:51 AM
Hey!
Paul assumed it right. The VBA is working perfect.
Thank you!
Cheers,
Julian
Aussiebear
11-17-2016, 06:30 PM
I'll mark it as Solved then.....
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.