Solved

Excel Copy Macro

Posted on 2011-09-07
6
187 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
[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 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

Industry Leaders: 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!

Question has a verified solution.

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

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
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 Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

730 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