Solved

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

Posted on 2016-07-15
6
38 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
  • 3
  • 2
6 Comments
 
LVL 39

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 16

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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
LVL 39

Accepted Solution

by:
als315 earned 500 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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
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 use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.

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