?
Solved

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

Posted on 2016-07-15
6
Medium Priority
?
43 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
Technology Partners: 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
After seeing numerous questions for Dynamic Data Validation I notice that most have used Visual Basic to solve the problem. This suggestion is purely formula based and can be used in multiple rows.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

770 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