How JustAnswer Works:
  • Ask an Expert
    Experts are full of valuable knowledge and are ready to help with any question. Credentials confirmed by a Fortune 500 verification firm.
  • Get a Professional Answer
    Via email, text message, or notification as you wait on our site.
    Ask follow up questions if you need to.
  • 100% Satisfaction Guarantee
    Rate the answer you receive.
Ask Richard Your Own Question
Richard, Consultant
Category: Programming
Satisfied Customers: 36526
Experience:  Programming and Network consultancy for 15+ years
Type Your Programming Question Here...
Richard is online now
A new question is answered every 9 seconds

Okay, I'm not versed in VBA so I need a lot of help. I want

Customer Question

okay, I'm not versed in VBA so I need a lot of help. I want to set up a macro in Excel 2016 to do a simple task such as centering an object within a specific cell or a range of cells. I've already been told that access is the best software to do that but I opened access and it all looks Greek to me. I've been using Word, Publisher, & Excel for several years with moderate success. I don't do this for a living I just run my church's monthly newsletter and I'm trying to create a directory of peoples names and photos where the photo is centered in each cell above the name, address, etc. I copied as code from the internet that is supposed to center an object but I can't seem to get a grip on the step by step needed to set up a macro to use this code. Help?
Submitted: 1 year ago.
Category: Programming
Expert:  The-PC-Guy replied 1 year ago.

first are you doing this in access or excel, because you mentioned both software.

Expert:  Richard replied 1 year ago.

Hi there and welcome

Sorry about the confusion, it is very clear what your asking.

If you already have the picture in the file, then you will want to use this code to center it

Sub CenterSelectedPicture()

Dim myR As Range
Set myR = Application.InputBox( _
"Center the selected picture on what cell?", , , , , , , 8)
Selection.ShapeRange.Top = myR.Top
Selection.ShapeRange.Left = myR.Left

Selection.ShapeRange.IncrementLeft (myR.Width - Selection.ShapeRange.Width) / 2

End Sub

If you have not yet actually added the picture to the file, then this code will allow you to both select the picture and insert it in a centered manner

Sub InsertCenterPicture()

Dim myR As Range
Set myR = Selection
'Insert the picture
ActiveSheet.Pictures.Insert( _
Application.GetOpenFilename( _
"JPG picture files (*.jpg),*.jpg", , "Select the picture")).Select
'center the picture on the current range selection
Selection.ShapeRange.IncrementLeft (myR.Width - Selection.ShapeRange.Width) / 2

End Sub

I can also do this code for you directly in your sheet, and have made the offer, please accept it and I can then do this for you

thank you