Simplification de Formule

willpower

XLDnaute Nouveau
Resolu: Simplification de Formule

Bonjour,

Cette formule va chercher et affiche l'image dans la colonne Q du numero qui a dans la colonne A.

Code:
Sub InsertionIMage() 'WD


        
    Sheets("DBReportQueryView").Activate
ActiveSheet.DrawingObjects.Delete
On Error Resume Next
Range("B4").Select
    
    Range("q2").Select
        ActiveSheet.Pictures.Insert(ThisWorkbook.Path & "\Order pictures\" & Range("a2").Value & ".jpg").Select
            Selection.ShapeRange.IncrementLeft 0
            Selection.ShapeRange.IncrementTop 0
            Selection.ShapeRange.LockAspectRatio = msoTrue
            Selection.ShapeRange.Height = 95
    
    Range("q3").Select
        ActiveSheet.Pictures.Insert(ThisWorkbook.Path & "\Order pictures\" & Range("a3").Value & ".jpg").Select
            Selection.ShapeRange.IncrementLeft 0
            Selection.ShapeRange.IncrementTop 0
            Selection.ShapeRange.LockAspectRatio = msoTrue
            Selection.ShapeRange.Height = 95
    
            
            
    Range("A1").Select
        
End Sub

Il y aurait t-il moyen de simplifier ma formule pour pas que j'aille a ecrire chaque rangé ?

Meric de votre aide!
 
Dernière édition:

deudecos

XLDnaute Impliqué
Re : Simplification de Formule

Salut willpower

Peut etre quelque chose comme ca :

Sub InsertionIMage() 'WD



Sheets("DBReportQueryView").Activate
ActiveSheet.DrawingObjects.Delete
On Error Resume Next

For i = 2 to Le nombre voulu
For j = 2 to Le nombre voulu
Range("q" & i).Select
ActiveSheet.Pictures.Insert(ThisWorkbook.Path & "\Order pictures\" & Range("a" & j).Value & ".jpg").Select
Selection.ShapeRange.IncrementLeft 0
Selection.ShapeRange.IncrementTop 0
Selection.ShapeRange.LockAspectRatio = msoTrue
Selection.ShapeRange.Height = 95

Next j
Next i

Range("A1").Select

End Sub

Bonne journee

Olivier
 
Dernière édition:

willpower

XLDnaute Nouveau
Re : Simplification de Formule

Salut willpower

Peut etre quelque chose comme ca :

Sub InsertionIMage() 'WD



Sheets("DBReportQueryView").Activate
ActiveSheet.DrawingObjects.Delete
On Error Resume Next

For i = 2 to Le nombre voulu
For j = 2 to Le nombre voulu
Range("q" & i).Select
ActiveSheet.Pictures.Insert(ThisWorkbook.Path & "\Order pictures\" & Range("a" & j).Value & ".jpg").Select
Selection.ShapeRange.IncrementLeft 0
Selection.ShapeRange.IncrementTop 0
Selection.ShapeRange.LockAspectRatio = msoTrue
Selection.ShapeRange.Height = 95

Next j
Next i

Range("A1").Select

End Sub

Bonne journee

Olivier

Salut Olivier,

Merci pour ton aide...mais...

Ca ne fonctionne pas... Il me met la meme image dans tous les rangés...(de la case Q2 a Q300 (le nombre voullu))
 

mutzik

XLDnaute Barbatruc
Re : Simplification de Formule

bonjour,

y' a un blem, tu indiques :
(ThisWorkbook.Path & "\Order pictures\"
mais ou se trouve le nom du fichier ? en colonne A ?
on pourrait avoir un bout de fichier, cela serait achement plus simple pour nous
 

mutzik

XLDnaute Barbatruc
Re : Simplification de Formule

re,

voili la macro corrigée, je ne sais pas pourquoi il avait mis deux boucles, notre ami Deudecos, mais bon, cela nous arrive à tous de faire des petites boulettes
 

Pièces jointes

  • Will.xls
    148 KB · Affichages: 62
  • Will.xls
    148 KB · Affichages: 67
  • Will.xls
    148 KB · Affichages: 69

Statistiques des forums

Discussions
312 483
Messages
2 088 780
Membres
103 961
dernier inscrit
sarrent74