Creating Macro using Ctrl+Shift+Up

KO69

New Member
Joined
Sep 12, 2012
Messages
7
Dear Prospective Helper,

I am currently in a situation where I am required to reformat a large spreadsheet. My current format is as follows:

Mr Smith
Ice CreamLondis
Ice CreamLondis
Mr Lewis
CrispsTescos
CrispsTescos
Ice CreamLondis
CrispsTescos
Ice CreamTescos
Ice CreamLondis
Mrs Jones
ChocolatesCo-op
Ice CreamLondis
ChocolatesCo-op
ChocolatesCo-op
ChocolatesCo-op

<colgroup><col><col></colgroup><tbody>
</tbody>


AND I need to get it into the following format, where the subheading (name) is in a column to the left of the relevant columns:

Mr Smith
Mr SmithIce CreamLondis
Mr SmithIce CreamLondis
Mr Lewis
Mr LewisCrispsTescos
Mr LewisCrispsTescos
Mr LewisIce CreamLondis
Mr LewisCrispsTescos
Mr LewisIce CreamTescos
Mr LewisIce CreamLondis
Mrs Jone
Mrs JoneChocolatesCo-op
Mrs JoneIce CreamLondis
Mrs JoneChocolatesCo-op
Mrs JoneChocolatesCo-op
Mrs JoneChocolatesCo-op

<colgroup><col><col><col></colgroup><tbody>
</tbody>

I have around 30,000 rows, and about 7,000 names to do this for, and am unable to 'record' a macro to automate this process (given my limited knowledge of excel.)

Please let me know if it is possible to automate this process using macros.

Many Thanks,

KO
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Assuming that data is in columns B and C and starts in row 1, you could enter in A2:
=IF(C2="","",IF(C1="",B1,A1))
and copy down
 
Upvote 0
Hi,

Insert the new column before the list (My original used colums A and B).
Open VBA and put in a formula with this code:
Code:
Option Explicit

Sub Copy_name()

    Dim R As Long
    Dim NameRng
    
    R = 1
    While Cells(R, 2).Value <> ""
        'Last name cell
        If Cells(R, 3).Value = "" Then
            NameRng = Cells(R, 2).Address
        Else
            Range(NameRng).Copy Cells(R, 1)
        End If
        R = R + 1
    Wend
End Sub

From the sheet run the macro (Alt-F8).

Is this what you were looking for?

Paul
 
Upvote 0
Try this:-
This on the basis that "Mr Smith start in "A1"
Code:
[COLOR="Navy"]Sub[/COLOR] MG12Sep48
[COLOR="Navy"]Dim[/COLOR] Rng     [COLOR="Navy"]As[/COLOR] Range
[COLOR="Navy"]Dim[/COLOR] Dn      [COLOR="Navy"]As[/COLOR] Range
[COLOR="Navy"]Dim[/COLOR] Temp    [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]String[/COLOR]
application.ScreenUpdating = False
Columns("A:A").Insert
[COLOR="Navy"]Set[/COLOR] Rng = Range(Range("B1"), Range("B" & Rows.Count).End(xlUp))
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Dn [COLOR="Navy"]In[/COLOR] Rng
    [COLOR="Navy"]If[/COLOR] Dn.Offset(, 1) = vbNullString [COLOR="Navy"]Then[/COLOR]
        Temp = Dn
    [COLOR="Navy"]Else[/COLOR]
        Dn.Offset(, -1) = Temp
    [COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]Next[/COLOR] Dn
application.ScreenUpdating = Tru
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0
Dear RoryA,

You are an absolute star!

You have saved me countless hours or trying to create a macro, and now my database will be set up in at least 1/10 of the time.

Many Thanks,

KO69

:biggrin:
 
Upvote 0
Dear RoryA, MickG and DeBeuz,


Thank you all for the help!

A quick question as to whether it would be most time efficient to use RoryA's, MickG's or
DeBeuz's suggestions, given that this code will be used on a 'source' spreadsheet, which will feed into about 7 spreadsheets filled with 'if' functions.

Many Thanks,

KO69

 
Upvote 0
All you have to do for mine is type that formula once, double-click the fill handle then copy and paste special - values if required. I suspect it will be faster than looping VBA but you can always test it. :)
 
Upvote 0

Forum statistics

Threads
1,215,042
Messages
6,122,810
Members
449,095
Latest member
m_smith_solihull

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