Making a fixed range dynamic in a macro that puts picture in comment

puupanda

New Member
Joined
Nov 25, 2014
Messages
8
I have the following macro that will take the url address (which is a link to a picture on a website) and create a picture of it on comment field. The problem is that I have to manually change the range of the cells including the urls. I would like to be able to only select the first cell and the macro would start making Picturecomments from there until the last row with data. E.g. I have urls in column B starting from row 3. I want to be able to select cell B3 and then run the macro. The macro should then run the insert picture into comment code from B3 until the last row with url in column B.
Code:
    Set rng = .Range("BM1:BM" & .Range("BM" & .Rows.Count).End(xlUp).Row)Set rng = .Range("BM1:BM" & .Range("BM" & .Rows.Count).End(xlUp).Row)
is the part that needs to be changed. Here is the whole macro. Im a novice in excel (understand some VBA)and I know this isn't anything huge but It will make my life so much easier.
Code:
Sub PicturesToCommentField()
Dim rng As Range, cell As Range
With ActiveSheet
' ref on the code [URL]http://www.mrexcel.com/forum/excel-questions/730664-insert-image-into-comment.html[/URL]

Set rng = .Range("BM1:BM" & .Range("BM" & .Rows.Count).End(xlUp).Row)
 
If Right(Selection.Value, 3) = "jpg" Then

 
End If
End With

For Each cell In rng
cell.Select
On Error Resume Next
If Selection.Value <> "" Then
Selection.AddComment
Selection.Comment.Visible = False
Selection.Comment.Text Text:=""
Selection.Comment.Visible = True
Selection.Comment.Shape.Select True

Selection.ShapeRange.LockAspectRatio = msoFalse
Selection.ShapeRange.Height = 250
Selection.ShapeRange.Width = 250

Selection.ShapeRange.Fill.ForeColor.RGB = RGB(255, 255, 255)
Selection.ShapeRange.Fill.UserPicture ActiveCell.Value
ActiveCell.Comment.Visible = False
Else
End If
Next

    
End Sub
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
On a side note. Would be awesome to be able to also get the properties of the picture behind the url (by properties I mean size and resolution) on e.g. the next column.
 
Upvote 0

Forum statistics

Threads
1,223,248
Messages
6,171,011
Members
452,374
Latest member
keccles

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