Solved

Copy/Paste Macro

Posted on 2011-03-18
6
368 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
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
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 …

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now