Solved

Excel Copy Macro

Posted on 2011-09-07
6
184 Views
Last Modified: 2012-05-12
I have data in 2 columns A and B.  I want to start in row 1 and copy the value in column B.  Then I need to go down column A and paste the value of B for each cell that it finds a match in column A.  When it finds a new number in B, it will not appear again.  Example:

A                                             B
10                                            Masonry
10                                            Masonry
10                                            Masonry
10                                            Masonry
10                                            Masonry
20                                            Drywall
20                                            Drywall
20                                            Drywall
30                                            Mosaic
30                                            Mosaic
0
Comment
Question by:Hamilj03
6 Comments
 
LVL 5

Expert Comment

by:slycoder
ID: 36497829
Try Copying Unique items using "Sort and Filter":

1) Add an unique title to each column
2) select both columns
3) Click on - Data - Sort & Filter Section - Advanced
4) click on copy to another location
5) in the Copy to box - click on an empty area of your spreadsheet to copy the new list to
6) check the Unique records only box and click on OK

Hope this helps


0
 
LVL 4

Expert Comment

by:SafetyFish
ID: 36498111
Just copy this into a module and link it to a button (or simply run it using F5 or F8).

The code assumes the format give above, but does ask the user to give the cell address of column "A" in the above example.

Sub Copy()
Dim rngNumbers As Range, strNumRangeAdd As String
Dim cell As Range, arrNumsUsed() As Long
Dim intArrUB As Integer, i As Integer
Dim bUsed As Boolean, strCopyValue As String

strNumRangeAdd = InputBox("Please give column range with guide numbers, e.g. A2:A365")
Set rngNumbers = Range(strNumRangeAdd)
intArrUB = 0
bUsed = False

For Each cell In rngNumbers
    bUsed = False
    If intArrUB = 0 Then
        ReDim Preserve arrNumsUsed(1)
        arrNumsUsed(1) = cell.Value
        intArrUB = UBound(arrNumsUsed)
        bUsed = True
        strCopyValue = cell.Offset(0, 1).Value
    End If
    i = 1
    If intArrUB > 0 Then
        For i = 1 To intArrUB
            If arrNumsUsed(i) = cell.Value Then
                bUsed = True
            End If
        Next i
    End If
    If bUsed = False Then
        ReDim Preserve arrNumsUsed(intArrUB + 1)
        intArrUB = UBound(arrNumsUsed)
        arrNumsUsed(intArrUB) = cell.Value
        strCopyValue = cell.Offset(0, 1).Value
    End If
    cell.Offset(0, 1).Value = strCopyValue
Next cell
End Sub
0
 

Author Comment

by:Hamilj03
ID: 36498276
Safety,

It seems to work some times but not others.  I may have misled you when I said that they will not be used again.  What I meant was that they are in sequential order.  you will go down the list copying values.  Once you find a new value, then the value being copied will be changed.
0
 

Accepted Solution

by:
Hamilj03 earned 0 total points
ID: 36498312
Got it.
Sub copycell()
Dim numerial1 As Integer
Dim numerial2 As Integer
Dim description1 As String

    Range("D2").Select
    numerial1 = ActiveCell.Value
    ActiveCell.Offset(0, 1).Select
    description1 = ActiveCell.Value
    ActiveCell.Offset(1, -1).Select
    numerial2 = ActiveCell.Value
Do
    
    If numerial1 = numerial2 Then
        ActiveCell.Offset(0, 1).Select
        ActiveCell.Value = description1
        
    Else
        numerial1 = ActiveCell.Value
        ActiveCell.Offset(0, 1).Select
        description1 = ActiveCell.Value
    End If
    ActiveCell.Offset(1, -1).Select
    numerial2 = ActiveCell.Value
Loop Until IsEmpty(ActiveCell)

End Sub

Open in new window

0
 
LVL 50

Expert Comment

by:Ingeborg Hawighorst
ID: 37087207
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Sparklines have been introduced with Excel 2010 and are a useful tool for creating small in-cell charts, used for example in dashboards. Excel 2010 offers three different types of Sparklines: Line, Column and Win/Loss. What it does not offer is a…
How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

920 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

16 Experts available now in Live!

Get 1:1 Help Now