locked
VBA to format text RRS feed

  • Question

  • Hello,

    While trying to learn VBA I'd appreciate help to permit me to use ActiveCell.Orientation = xlUpward to do the following:

    =IF(Range(A1:A5)="EX",True,False). When True I'd like to activate the ActiveCell.Orientation = xlUpward and the text changed to color=red and BOLD, else do nothing.  In case it isn't clear, I'd like the text in each cell turned upward when the text "EX" is entered in a cell in the A1:A5 range and that EX text changed to bold red.

    Thanks for any assistance.

    Friday, June 3, 2016 5:45 PM

Answers

  • Hi

    Something like this:

    Sub EXformat()
    Dim i As Integer
    For i = 1 To 5
        If Cells(i, 1).Value = "EX" Then
        With Cells(i, 1)
            .Orientation = 90
            .Font.ColorIndex = 3
            .Font.Bold = True
        End With
        End If
        Next i
    End Sub

    If you want an Event macro that will make the change automatic each time you type in the cells then this goes in a Worksheet Module.

    Private Sub Worksheet_Change(ByVal Target As Range)
     If Target.Cells.Count > 1 Then Exit Sub
     If Not Intersect(Target, Range("A1:A5")) Is Nothing Then
        If Target.Value = "EX" Then
        With Target
            .Orientation = 90
            .Font.ColorIndex = 3
            .Font.Bold = True
        End With
        End If
        End If
    End Sub


    Cimjet


    Friday, June 3, 2016 11:08 PM

All replies

  • Hi

    Something like this:

    Sub EXformat()
    Dim i As Integer
    For i = 1 To 5
        If Cells(i, 1).Value = "EX" Then
        With Cells(i, 1)
            .Orientation = 90
            .Font.ColorIndex = 3
            .Font.Bold = True
        End With
        End If
        Next i
    End Sub

    If you want an Event macro that will make the change automatic each time you type in the cells then this goes in a Worksheet Module.

    Private Sub Worksheet_Change(ByVal Target As Range)
     If Target.Cells.Count > 1 Then Exit Sub
     If Not Intersect(Target, Range("A1:A5")) Is Nothing Then
        If Target.Value = "EX" Then
        With Target
            .Orientation = 90
            .Font.ColorIndex = 3
            .Font.Bold = True
        End With
        End If
        End If
    End Sub


    Cimjet


    Friday, June 3, 2016 11:08 PM
  • Hi AlaDiver,

    Here I think suggestion given by the Cimjet can solve your issue. I have check the suggestion given by the Cimjet and find that it's working as per your requirement so I would recommend you to check the suggestion of Cimjet.

    if you think it worked for you that kind mark the suggestion as an Answered.

    if still have any problem regarding that please let us know so that we can help you further.

    Regards

    Deepak


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Sunday, June 5, 2016 11:59 PM