Solved

Copy/Paste Macro

Posted on 2011-03-18
6
372 Views
Last Modified: 2012-05-11
Hello,

I need a macro that will:
 1. Copy the Star in M1
 2. Paste the Star in M1 in cell in the cells with "• "  in the cell Range M:DL

Please see the attached document.

Any Takers?
Test.xlsm
0
Comment
Question by:ctownsen80
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 24

Expert Comment

by:StephenJR
ID: 35168949
This perhaps?
Sub Macro1()

Dim r As Range

Application.ScreenUpdating = False

With Sheets("Test")
    .Shapes("AutoShape 6").Copy
    For Each r In .Range("M10:DL254")
        If r.Value <> "" Then
            r.PasteSpecial
            .Shapes(.Shapes.Count).Left = r.Left
            .Shapes(.Shapes.Count).Top = r.Top
        End If
    Next r
End With

Application.ScreenUpdating = True

End Sub

Open in new window

0
 
LVL 14

Expert Comment

by:peetjh
ID: 35169071
This code will do the same but if you change the file and need to go more than 254 rows this will accomidate it.
Sub Macro1()

Dim myRange As Range
Dim lastrec As Long
lastrec = [a65536].End(xlUp).Row
Application.ScreenUpdating = False
Set myRange = Range("M10", "DL" & lastrec)
For Each cell In myRange
    If cell.Value <> "" Then
    ActiveSheet.Shapes.Range(Array("AutoShape 6")).Select
    Selection.Copy
    cell.Select
    ActiveSheet.Paste
    End If
Next cell
End Sub

Open in new window

0
 
LVL 29

Expert Comment

by:leonstryker
ID: 35169093
I think using the Find method woudl be a lot faster:

Sub CopyStar()
Dim objStar As Shape
Dim lCount As Long, lngTotal As Long
    Application.ScreenUpdating = False
    Set objStar = ActiveSheet.Shapes("AutoShape 6")
    objStar.Copy
    lngTotal = WorksheetFunction.CountIf(Cells, " •")
    For lCount = 1 To lngTotal
        Cells.Find(What:=" •", After:=ActiveCell, SearchDirection:=xlNext).Activate
        ActiveSheet.Paste
        Application.StatusBar = "Pasting Star " & lCount & " of " & lngTotal
    Next
    Application.StatusBar = False
End Sub
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:ctownsen80
ID: 35182657
leonstryker,

Thanks a bunch!  Your method works almost perfectly.  However the copystar code stops in the actual file in row 395.  I actually have 1100 row that may need to be updated.  Please advise.
0
 
LVL 29

Accepted Solution

by:
leonstryker earned 500 total points
ID: 35193190
However the copystar code stops in the actual file in row 395.

Not sure what you mean by that. Do you mean it does not replace all of the items? If so, try this:

Sub CopyStar()
Dim objStar As Shape
Dim lCount As Long, lngTotal As Long
    Application.ScreenUpdating = False
    Range("A1").Select
    Set objStar = ActiveSheet.Shapes("AutoShape 6")
    objStar.Copy
    lngTotal = WorksheetFunction.CountIf(Cells, " •")
    For lCount = 1 To lngTotal
        Cells.Find(What:=" •", After:=ActiveCell, SearchDirection:=xlNext).Activate
        ActiveSheet.Paste
        Application.StatusBar = "Pasting Star " & lCount & " of " & lngTotal
    Next
    Range("A1").Select
    Application.StatusBar = False
End Sub
0
 

Author Closing Comment

by:ctownsen80
ID: 35194533
This guy is great!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question