+ Reply to Thread
Results 1 to 3 of 3

Excel VBA help rearranging data on worksheet

Hybrid View

hauntedfarm Excel VBA help rearranging... 12-20-2013, 08:11 AM
MickG Re: Excel VBA help... 12-20-2013, 09:13 AM
hauntedfarm Re: Excel VBA help... 01-17-2014, 10:15 AM
  1. #1
    Registered User
    Join Date
    11-25-2013
    Location
    ohio
    MS-Off Ver
    Excel 2007
    Posts
    2

    Excel VBA help rearranging data on worksheet

    I have not worked with VBA that long and I have an initial worksheet that contains property info, the key of the row will be the customer no.
    Each customer can have unlimited properties. For the first instance of the customer id I need it to copy to the worksheet2 (or leave it in the same spaces) in the first spaces,
    for the second instance of the customer number it will append the data to sheet 2( or row 1 sheet 1 for the existing customer) in the same row but in spaces for second info etc. See below

    INITIAL FILE
    customer id property1 amtoffered1 parcel address1 property2 amtoffered2 percel2 address2
    123 65734 1000 b 123 Lane
    123 23114 500 a 222 dice
    444 23443 100 c 11 smoke

    FINAL WORKSHEET 2
    customer id property1 amtoffered1 parcel address1 property2 amtoffered2 percel2 Address2
    123 65734 1500 b 123 Lane 23114 500 a 222 dice
    444 23443 100 c 11 smoke

  2. #2
    Forum Expert MickG's Avatar
    Join Date
    11-23-2007
    Location
    Banbury,Oxfordshire
    Posts
    2,650

    Re: Excel VBA help rearranging data on worksheet

    Try this:-
    NB:- This code will modify your original Data sheet, Please make Backup.!!!
    Sub MG20Dec35
    Dim Rng         As Range
    Dim Dn          As Range
    Dim n           As Long
    Dim nRng        As Range
    Dim Q           As Variant
    Dim oHds        As Variant
    oHds = Array("id", "property", "amtoffered", "perce", "address")
        Set Rng = Range(Range("A2"), Range("A" & Rows.Count).End(xlUp))
            With CreateObject("scripting.dictionary")
                .CompareMode = vbTextCompare
    For Each Dn In Rng
      
        If Not .Exists(Dn.Value) Then
            .Add Dn.Value, Array(Dn.Offset(, 1), 0, 1)
        Else
            ReDim ray(1 To 5)
            Q = .Item(Dn.Value)
                Q(2) = Q(2) + 1
                Q(1) = Q(1) + 5
                For n = 0 To UBound(oHds)
                    If n > 0 Then
                        ray(n + 1) = oHds(n) & Q(2)
                    Else
                        ray(n + 1) = oHds(n)
                    End If
                 Next n
                    Range("B1").Offset(, Q(1)).Resize(, 5) = ray
                    Dn.Offset(, 1).Resize(, 5).Copy Q(0).Offset(, Q(1))
                If nRng Is Nothing Then
                    Set nRng = Dn
                Else
                    Set nRng = Union(nRng, Dn)
                End If
           .Item(Dn.Value) = Q
        End If
    Next
    End With
    If Not nRng Is Nothing Then nRng.EntireRow.Delete
    End Sub
    Regards Mick

  3. #3
    Registered User
    Join Date
    11-25-2013
    Location
    ohio
    MS-Off Ver
    Excel 2007
    Posts
    2

    Re: Excel VBA help rearranging data on worksheet

    Mick,
    Trying code right now and working on it, have been sick, so I am slightly behind. I am so grateful for your help. I will let you know how it goes.
    Thanks,
    Kim

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. rearranging cells in a worksheet
    By louster50 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 12-04-2013, 10:24 PM
  2. Rearranging Data Within a Single Worksheet
    By pugsly8422 in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 01-20-2012, 01:13 PM
  3. Excel 2007 : Rearranging data
    By gunner in forum Excel General
    Replies: 4
    Last Post: 10-12-2010, 10:12 AM
  4. Replies: 4
    Last Post: 09-14-2009, 09:57 PM
  5. Rearranging Data in Excel
    By Keensie in forum Excel General
    Replies: 1
    Last Post: 04-21-2006, 09:03 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1