Pasting image at the end of cell

harvey121

New Member
Joined
Nov 27, 2018
Messages
20
Hi All,
In the below link of my data, I have to compare the values of the two cells side by side. Now I have to place an arrow(image) for the values in column A which are greater than that of B.

SmWGk4L
https://ibb.co/SmWGk4L
SmWGk4L


Is this possible to automate via VBA? If so, kindly help me on this. I would really appreciate your help.
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
.
You can accomplish your goal using CONDITIONAL FORMATTING.

This solution uses a macro / VBA CODE :

Code:
Option Explicit




Sub Test()


    Dim lngI As Long
    Dim CharToAdd As String
    Dim ColourToUse As Long


    For lngI = 2 To 7


        With Worksheets("Sheet1")
            If .Cells(lngI, 1) > .Cells(lngI, 2) Then
                CharToAdd = " é"        'Up arrow.
                ColourToUse = -16776961 'Red   '-11489280 'Green.
            ElseIf .Cells(lngI, 1) < .Cells(lngI, 2) Then
                CharToAdd = ""    '" ê"        'Down arrow.
                'ColourToUse = -16776961 'Red.
            Else
                CharToAdd = ""      '" è"        'Right arrow.
                'ColourToUse = -16711681 'Yellow.
            End If


            'Add the character to the end of the number.
            'Note - cell is now a text string.
            .Cells(lngI, 1) = .Cells(lngI, 1) & CharToAdd


            'Format last character in cell.
            With .Cells(lngI, 1).Characters(Start:=Len(.Cells(lngI, 1)), Length:=1).Font
                .Name = "Wingdings"
                .Color = ColourToUse
            End With
        End With


    Next lngI


End Sub
 
Upvote 0
Hi,
After running this macro the arrows are correctly placed with column 1 values greater than column 2 but the values in column 1 which are lesser or equal to column 2 get changed into some form of images/icons. After clicking on these I can see that the formula box shows the value correctly although it's displaying incorrectly in the cell.

.
You can accomplish your goal using CONDITIONAL FORMATTING.

This solution uses a macro / VBA CODE :

Code:
Option Explicit




Sub Test()


    Dim lngI As Long
    Dim CharToAdd As String
    Dim ColourToUse As Long


    For lngI = 2 To 7


        With Worksheets("Sheet1")
            If .Cells(lngI, 1) > .Cells(lngI, 2) Then
                CharToAdd = " é"        'Up arrow.
                ColourToUse = -16776961 'Red   '-11489280 'Green.
            ElseIf .Cells(lngI, 1) < .Cells(lngI, 2) Then
                CharToAdd = ""    '" ê"        'Down arrow.
                'ColourToUse = -16776961 'Red.
            Else
                CharToAdd = ""      '" è"        'Right arrow.
                'ColourToUse = -16711681 'Yellow.
            End If


            'Add the character to the end of the number.
            'Note - cell is now a text string.
            .Cells(lngI, 1) = .Cells(lngI, 1) & CharToAdd


            'Format last character in cell.
            With .Cells(lngI, 1).Characters(Start:=Len(.Cells(lngI, 1)), Length:=1).Font
                .Name = "Wingdings"
                .Color = ColourToUse
            End With
        End With


    Next lngI


End Sub
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,249
Members
452,623
Latest member
Techenthusiast

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top