Moving Any Text or Any Number

spyldbrat

Board Regular
Joined
May 5, 2002
Messages
211
Office Version
  1. 365
In column A of my spreadsheet on row 1, I have a clients name, on row 2 I have the client ID # and row 3 and 4 I have dates associated with that particular client. Row 5 contains another clients name, row 6 is the client ID # and row's 7 to 14 contain dates and so...The number of dates associated with each client will vary.

I need to move the clients name and client ID# to columns B & C - NEXT to the dates for each client. This would also involve inserting a column so that the data in column C shifts one to the right.

This is what it currently looks like:
A
1 CLIENT NAME 1
2 CLIENT ID 1
3 DATE (Client 1)
4 DATE (Client 1)
5 CLIENT NAME 2
6 CLIENT ID 2
7 DATE (Client 2)
8 DATE (Client 2)
9 DATE (Client 2)
10 DATE (Client 2)
11 DATE (Client 2)
12 DATE (Client 2)
13 DATE (Client 2)

This is what I need it to look like:
A B C

1 DATE (Client 1) CLIENT NAME 1 CLIENT ID 1
2 DATE (Client 1) CLIENT NAME 1 CLIENT ID 1
3
4 DATE (Client 2) CLIENT NAME 2 CLIENT ID 2
5 DATE (Client 2) CLIENT NAME 2 CLIENT ID 2
6 DATE (Client 2) CLIENT NAME 2 CLIENT ID 2
7 DATE (Client 2) CLIENT NAME 2 CLIENT ID 2
8 DATE (Client 2) CLIENT NAME 2 CLIENT ID 2
9 DATE (Client 2) CLIENT NAME 2 CLIENT ID 2
10 DATE (Client 2) CLIENT NAME 2 CLIENT ID 2
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Are the Client IDs alphanumeric or numeric?

Would you mind posting a small sample of what the data actually looks like?

Also, what row does that data start on (is there a header row)?
 
Last edited:
Upvote 0
Depending on the formats of your data, this code may work:
Code:
Sub MyMacro()

    Dim myRow As Long
    Dim lastRowDate As Boolean
    Dim myClient As String
    Dim myID As String
    
    Application.ScreenUpdating = False
    
'   Set initial values
    lastRowDate = True
    myRow = 1
    
'   Loop through rows
    Do
'       See if we start a new client
        If lastRowDate And Not (IsDate(Cells(myRow, "A"))) Then
'           Capture client
            myClient = Cells(myRow, "A")
'           Clear current row
            Cells(myRow, "A").ClearContents
'           Set lastRowDate
            lastRowDate = False
'           Go to next row
            myRow = myRow + 1
        Else
'           What to do if second row
            If (lastRowDate = False) And Not (IsDate(Cells(myRow, "A"))) Then
'               Capture ID
                myID = Cells(myRow, "A")
'               Set lastRowDate
                lastRowDate = False
'               Delete current row
                Rows(myRow).Delete
            Else
'               Handle date row
                If IsDate(Cells(myRow, "A")) Then
'                   Assign values
                    Cells(myRow, "B") = myClient
                    Cells(myRow, "C") = myID
'                   Set lastRowDate
                    lastRowDate = True
'                   Go to next row
                    myRow = myRow + 1
                End If
            End If
        End If
    Loop Until Cells(myRow, "A") = ""
    
    Application.ScreenUpdating = True

End Sub
 
Upvote 0

Forum statistics

Threads
1,223,909
Messages
6,175,315
Members
452,634
Latest member
cpostell

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top