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

x
?
Solved

Move contents of selected cells to same row into next column adjacent

Posted on 2016-07-15
6
Medium Priority
?
45 Views
Last Modified: 2016-07-16
1.  In column A there is a list of suburb names, state abbreviations, postcodes.
2.  There are also some rows that have only the state abbreviation and postcode.

I want to move the state abbreviation and postcode to the cell in the next column immediately adjacent, on the same row.
Theses are the state abbreviations VIC, TAS, NSW, SA, WA, QLD, ACT

See example of original and required in attached file.
EE-Postcodes-problem-1.xlsx
0
Comment
Question by:gregfthompson
[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
  • 3
  • 2
6 Comments
 
LVL 40

Expert Comment

by:als315
ID: 41713834
You can use macro like:
Sub move_PO()
Dim i As Long
Dim j As Integer
Dim ws As Object
Dim PO
Set ws = ActiveSheet
PO = Array("VIC", "TAS", "NSW", "SA", "WA", "QLD", "ACT")
i = 2
With ws
  Do Until .Cells(i, 1) = "" And .Cells(i, 3) = ""
    For j = 0 To UBound(PO)
        If InStr(1, .Cells(i, 1), PO(j) & "", vbBinaryCompare) = 1 Then
            .Cells(i, 3) = .Cells(i, 1)
            .Cells(i, 1) = ""
            Exit For
        End If
    Next j
    i = i + 1
  Loop
End With
End Sub

Open in new window

Assign it to some key (in attached sample it is assigned to CTRL+SHIFT+A) and run on your sheet
EE-Postcodes-problem-1.xlsm
0
 

Author Comment

by:gregfthompson
ID: 41714534
Thanks.

It worked for some.

But there are still lots that did not move.

A larger list is attached.
EE-State-abbreviation-problem.xlsm
0
 
LVL 17

Expert Comment

by:Gerald Connolly
ID: 41714542
If this is a one off you could just use the text-2-columns function (on the Date Tab) in Excel and then manually edit the exceptions, then use the string join to give you a single cell (ie =c1 & " " & d1), then copy and paste special (Values)
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!

 
LVL 40

Accepted Solution

by:
als315 earned 2000 total points
ID: 41714605
I didn't expect empty rows. Try this function:
Sub move_PO()
Dim i As Long, LastRow As Long
Dim j As Integer
Dim ws As Object
Dim PO
PO = Array("VIC", "TAS", "NSW", "SA", "WA", "QLD", "ACT")
Set ws = ActiveSheet
With ws
.UsedRange 'Refresh UsedRange
LastRow = .UsedRange.Rows(.UsedRange.Rows.Count).Row

i = 2
  Do While i <= LastRow
    For j = 0 To UBound(PO)
        If InStr(1, .Cells(i, 1), PO(j) & " ", vbBinaryCompare) = 1 Then
            .Cells(i, 3) = .Cells(i, 1)
            .Cells(i, 1) = ""
            Exit For
        End If
    Next j
    i = i + 1
  Loop
End With
End Sub

Open in new window

EE-State-abbreviation-problem-1.xlsm
0
 

Author Comment

by:gregfthompson
ID: 41714848
Thanks.

That is brilliant.

Can you do a variation that moves the contents of any cell that does not contain a number, into the cell on the right on the same row?
0
 

Author Closing Comment

by:gregfthompson
ID: 41714960
Thanks heaps.

I've managed to work it out.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

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