Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Copy/Paste Macro

Posted on 2011-03-18
6
Medium Priority
?
375 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:JP
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
Independent Software Vendors: 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 2000 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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone 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

With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

610 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