[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Excel Copy Macro

Posted on 2011-09-07
6
Medium Priority
?
195 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
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

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…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
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 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.

656 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