Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Inserting Pictures into cells

hi,

Lets say I have a list of countries that gets sorts out depending on
certain things. I need Excel to insert the flag of the country in the
next column.

Is this possible?

Thanks for the help.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Inserting Pictures into cells

Turn on the macro recorder while you insert your picture manually
(insert=Picture=From File)

then turn of the macro recorder and modify the code to react to your
situation.

--
Regards,
Tom Ogilvy

wrote in message
oups.com...
hi,

Lets say I have a list of countries that gets sorts out depending on
certain things. I need Excel to insert the flag of the country in the
next column.

Is this possible?

Thanks for the help.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Inserting Pictures into cells

thx... but that's not what I meant.

Let me explain myself a little better.

I have a ranking of countries in column B (USA, England, Congo, etc).
The ranking may change when new data is entered. Lets say that at the
beginning the list was B1 England, B2 USA, B3 Congo. Then later when I
enter new data, the list might go B1 USA, B2 Congo, B3 England, etc. I
need column C to display the flag of the country and change everytime
the ranking changes.

I tried with this routine but column C (flags) doesn't refresh when the
ranking changes:

Private Sub Worksheet_Change(ByVal Target As Range)

Dim rng As Range
Dim rngFlags1 As Range
Dim pic As Picture, shp As Shape

On Error Resume Next
'Only insert the picture if it's in the area where they type
the Product Names
'Change "Products" to a range of cells where they'll be typing
in Product numbers
Set rngFlags1 = Intersect(Me.Range("Flags1"), Target)
On Error GoTo 0

If Not rngFlags1 Is Nothing Then 'They entered a product number
'Loop through each cell they entered in
' in case they copied several product numbers into several
cells
For Each rng In rngFlags1
'Remove the exisitng picture (shape) from the cell to the
right
For Each shp In Me.Shapes
If shp.TopLeftCell.Address = rng.Offset(0, 1).Address
Then shp.Delete
Next shp
'Insert the picture
On Error Resume Next
Set pic = ActiveSheet.Pictures.Insert("C:\Documents and
Settings\Sergio\My Documents\Flags\" & rng.Text & ".gif")
On Error GoTo 0
If Not pic Is Nothing Then 'The picture exists
With pic
.Height = rng.Offset(0, 1).Height
.Width = rng.Offset(0, 1).Width
.Left = rng.Offset(0, 1).Left
.Top = rng.Offset(0, 1).Top
End With

End If

Next rng

End If
End Sub

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Inserting Pictures into cells

If the user is manually making changes in column B, then the event should
fire.

--
Regards,
Tom Ogilvy


wrote in message
oups.com...
thx... but that's not what I meant.

Let me explain myself a little better.

I have a ranking of countries in column B (USA, England, Congo, etc).
The ranking may change when new data is entered. Lets say that at the
beginning the list was B1 England, B2 USA, B3 Congo. Then later when I
enter new data, the list might go B1 USA, B2 Congo, B3 England, etc. I
need column C to display the flag of the country and change everytime
the ranking changes.

I tried with this routine but column C (flags) doesn't refresh when the
ranking changes:

Private Sub Worksheet_Change(ByVal Target As Range)

Dim rng As Range
Dim rngFlags1 As Range
Dim pic As Picture, shp As Shape

On Error Resume Next
'Only insert the picture if it's in the area where they type
the Product Names
'Change "Products" to a range of cells where they'll be typing
in Product numbers
Set rngFlags1 = Intersect(Me.Range("Flags1"), Target)
On Error GoTo 0

If Not rngFlags1 Is Nothing Then 'They entered a product number
'Loop through each cell they entered in
' in case they copied several product numbers into several
cells
For Each rng In rngFlags1
'Remove the exisitng picture (shape) from the cell to the
right
For Each shp In Me.Shapes
If shp.TopLeftCell.Address = rng.Offset(0, 1).Address
Then shp.Delete
Next shp
'Insert the picture
On Error Resume Next
Set pic = ActiveSheet.Pictures.Insert("C:\Documents and
Settings\Sergio\My Documents\Flags\" & rng.Text & ".gif")
On Error GoTo 0
If Not pic Is Nothing Then 'The picture exists
With pic
.Height = rng.Offset(0, 1).Height
.Width = rng.Offset(0, 1).Width
.Left = rng.Offset(0, 1).Left
.Top = rng.Offset(0, 1).Top
End With

End If

Next rng

End If
End Sub



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Inserting Pictures into cells

The user doesn't make changes to column B. Column B updates itself
after data is entered in another table.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Inserting Pictures into cells

Then you would need to use the calculate event.

--
Regards,
Tom Ogilvy


wrote in message
oups.com...
The user doesn't make changes to column B. Column B updates itself
after data is entered in another table.



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Inserting Pictures into cells

and how do i do that?

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Inserting Pictures into cells

http://www.cpearson.com/excel/events.htm

--
Regards,
Tom Ogilvy


wrote in message
oups.com...
and how do i do that?



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Inserting Pictures cjohnson Excel Discussion (Misc queries) 2 April 2nd 08 07:00 PM
Inserting Pictures DamienO Excel Discussion (Misc queries) 2 October 31st 07 12:40 PM
Inserting Pictures Matthew[_2_] Excel Discussion (Misc queries) 3 July 14th 07 10:23 AM
Inserting pictures/autoshapes to certain cells ? Dus Excel Programming 1 May 18th 05 11:27 PM
inserting pictures Denny[_2_] Excel Programming 5 November 16th 04 01:49 AM


All times are GMT +1. The time now is 05:10 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"