Hi Ken,
I sade earlier that I wrote a code that dose the opposite. Evaluate a
cells value and pastes the proper shape. I will put it her. Maybe
somebody needs it. It's not the best one, the most efficient one but it
doses the job. I translated most of my comments. I call this code
throught a command button from a form.
Private Sub cmdfill_Click()
On Error GoTo eroare
GoTo start
eroare:
oldstatusbar = Application.DisplayStatusBar
Application.StatusBar = False
Application.DisplayStatusBar = oldstatusbar
MsgBox "Error number" & Err & ":" & Error(Err) & vbCrLf & "Se cere
interventia lui Mihai."
Unload frmintimpinare
Workbooks("tm macro.xls").Close False
End
start:
Dim lastrow As Long
Dim emptycol, lastrow, e As String
Dim mydocument As Worksheet
Dim shp As Shape
Dim c, s As Variant
'hide frmintimpinare
Unload frmwelcome
'Request patienes in statusbar
oldstatusbar = Application.DisplayStatusBar
Application.DisplayStatusBar = True
Application.StatusBar = "Patiens!! Se lucreaza cu cifre. Imediat
termin.
"
'Reveal all tabels
ActiveSheet.Outline.ShowLevels RowLevels:=0, ColumnLevels:=2
'last row
Range("B7:B100").Select
Selection.Find(what:="", after:=ActiveCell, LookIn:=xlFormulas,
lookat:=xlPart, _
searchorder:=xlByRows, searchdirection:=xlNext,
MatchCase:=False).Activate
lastrow = ActiveCell.row - 1
'Find cell "Activity/Activitate" and address
For Each a In Range("B4:EY4")
If a.Value = "Activity/Activitate" Then
adresaAA = a.Address
'Activate cell "Activity/Activitate"
Range(adresaAA).Activate
'Selecte till EY4 !! watch out for new projects!
Range(adresaAA & ":$EY$4").Select
Selection.Find(what:="", after:=ActiveCell, _
LookIn:=xlFormulas, lookat:=xlPart,
searchorder:=xlByColumns, searchdirection:=xlNext, _
MatchCase:=False).Activate
'find the letter of the empty column after "Activity/Activitate"
emptycol = "$" & Split(ActiveCell.Offset(0, -1).Address,
"$")(1)
lastrow = "$" & lastrow
'Define selection
e = Range(adresaAA).Offset(3, 1).Address & ":" & (emptycol &
lastrow)
Set myrange = ActiveSheet.Range(e)
'Count the grades
one = Application.WorksheetFunction.CountIf(myrange, 1)
two = Application.WorksheetFunction.CountIf(myrange, 2)
three = Application.WorksheetFunction.CountIf(myrange, 3)
four = Application.WorksheetFunction.CountIf(myrange, 4)
'Write grades
ActiveCell.Offset(lastrow - 3, -1).FormulaR1C1 = "1=" & one
ActiveCell.Offset(lastrow - 2, -1).FormulaR1C1 = "2=" & two
ActiveCell.Offset(lastrow - 1, -1).FormulaR1C1 = "3=" & three
ActiveCell.Offset(lastrow, -1).FormulaR1C1 = "4=" & four
End If
Next
'Back to A1
Range("A1").Select
'check if the shapes in the legend have proper names "Group 1, 2, 3,
4"
'clean cell to be used
Range("EZ7:EZ8000").Select
Selection.ClearContents
Range("A1").Activate
'write the names of all the shapes in EZ7:EZ8000
Set mydocument = ActiveSheet
Range("EZ7").Activate
For Each shp In mydocument.Shapes
c = Left(shp.Name, 8)
ActiveCell.FormulaR1C1 = c
ActiveCell.Offset(rowOffset:=1, columnOffset:=0).Activate
Next
'look for the correct names or end
With ActiveSheet.Range("EZ7:EZ8000")
Set s = .Find("Group 1", ActiveCell, xlFormulas, xlWhole, xlByRows,
xlNext, False)
If s Is Nothing Then
Range("A1").Activate
MsgBox "From the legend is missing the shape with the name" & vbCrLf &
" Group 1" & vbCrLf & _
"Rename the first shape from legend to: Group 1", vbOKOnly, "ERROR
Name"
Range("EZ7:EZ8000").Select
Selection.ClearContents
Range("A1").Activate
oldstatusbar = Application.DisplayStatusBar
Application.StatusBar = False
Application.DisplayStatusBar = oldstatusbar
Workbooks("tm macro.xls").Close False
End
Else
Set s = .Find("Group 2", ActiveCell, xlFormulas, xlWhole, xlByRows,
xlNext, False)
If s Is Nothing Then
Range("A1").Activate
MsgBox "From the legend is missing the shape with the name" &
vbCrLf & " Group 2" & vbCrLf & _
"Rename the first shape from legend to: Group 2", vbOKOnly, "ERROR
Name"
Range("EZ7:EZ8000").Select
Selection.ClearContents
Range("A1").Activate
oldstatusbar = Application.DisplayStatusBar
Application.StatusBar = False
Application.DisplayStatusBar = oldstatusbar
Workbooks("tm macro.xls").Close False
End
Else
Set s = .Find("Group 3", ActiveCell, xlFormulas, xlWhole,
xlByRows, xlNext, False)
If s Is Nothing Then
Range("A1").Activate
MsgBox "Din Legenda lipseste desenul cu numele" & vbCrLf & "
Group 3" & vbCrLf & _
"Redenumiti al treilea desen din Legenda: Group 3", vbOKOnly,
"EROARE Nume"
Range("EZ7:EZ8000").Select
Selection.ClearContents
Range("A1").Activate
oldstatusbar = Application.DisplayStatusBar
Application.StatusBar = False
Application.DisplayStatusBar = oldstatusbar
Workbooks("tm macro.xls").Close False
End
Else
Set s = .Find("Group 4", ActiveCell, xlFormulas, xlWhole,
xlByRows, xlNext, False)
If s Is Nothing Then
Range("A1").Activate
MsgBox "Din Legenda lipseste desenul cu numele" & vbCrLf &
" Group 4" & vbCrLf & _
"Redenumiti al patrulea desen din Legenda: Group 4",
vbOKOnly, "EROARE Nume"
Range("EZ7:EZ8000").Select
Selection.ClearContents
Range("A1").Activate
oldstatusbar = Application.DisplayStatusBar
Application.StatusBar = False
Application.DisplayStatusBar = oldstatusbar
Workbooks("tm macro.xls").Close False
End
End If
End If
End If
End If
End With
'clean
Range("EZ7:EZ8000").Select
Selection.ClearContents
Range("A7").Activate
'for each cell find the address C7:EY200
For Each c In Range("C7:EY200")
e = c.Address
'test the value in the cell and past the proper shape and empty the
cell
If c.Value = 1 Then
Range(e).Activate
ActiveSheet.Shapes("group 1").Copy
ActiveCell.PasteSpecial
ActiveCell.ClearContents
Else
If c.Value = 2 Then
Range(e).Activate
ActiveSheet.Shapes("group 2").Copy
ActiveCell.PasteSpecial
ActiveCell.ClearContents
Else
If c.Value = 3 Then
Range(e).Activate
ActiveSheet.Shapes("group 3").Copy
ActiveCell.PasteSpecial
ActiveCell.ClearContents
Else
If c.Value = 4 Then
Range(e).Activate
ActiveSheet.Shapes("group 4").Copy
ActiveCell.PasteSpecial
ActiveCell.ClearContents
End If
End If
End If
End If
Next
'establish the properties for moving and redimensioning of the shapes
mydocument.Shapes.SelectAll
'Set sr = Selection.ShapeRange
With Selection
..Placement = xlMoveAndSize
..PrintObject = True
End With
Range("A7").Activate
'finish
'Old statusbar
Application.StatusBar = False
Application.DisplayStatusBar = oldstatusbar
'Unload frmwelcome
MsgBox "Finish." & vbCr & vbLf & "Don't forget to save!", vbOKOnly,
"Info"
Workbooks("tm macro.xls").Close False
End
End Sub