+ Reply to Thread
Results 1 to 5 of 5

VB Code to reorganize data

Hybrid View

  1. #1
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    VB Code to reorganize data

    Hello:

    Please refer to attached file.
    I have data as shown in Sheet1.
    I need BN Code to transpose these data as shown in Sheet2.
    (Here i am showing for 2 Vendors, but need to go thru all data).
    Just to let you know that in Sheet2,
    Column B will be todays date,
    Column A will be "YES"
    Column C will be "Bill"
    Colunn D will be Bill#
    Colunn E will be Name of Vendor
    Column F will be "Account Payable"
    Column L will be Amount.

    Let me know if you have any questions.
    Thanks.
    Riz
    Attached Files Attached Files

  2. #2
    Forum Expert Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    Office 2003, 2010, 2013, 2016, 365
    Posts
    3,284

    Re: VB Code to reorganize data

    Sub Reorg()
    Dim ws As Worksheet
    Dim headings As String
    Dim supplier As String
    Dim lastrow As Long
    Dim nextrow As Long
    Dim i As Long
    
        Applic ation.ScreenUpdating = False
        
        headings = "New Transaction,Date,Type,Bill#,Name,Source Account,Account,Class,Item,Qty,Price Each,Amount"
        
        Set ws = Worksheets("Sheet2")
        If ws.Range("A1") = vbNullString Then
        
            ws.Range("A1").Resize(, Len(headings) - Len(Replace(headings, ",", vbNullString)) + 1).Value = Split(headings, ",")
            nextrow = 2
        Else
        
            nextrow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
        End If
        
        With Worksheets("Sheet1")
        
            lastrow = .Cells(.Rows.Count, "E").End(xlUp).Row
            i = 1
            
            For i = i To lastrow
            
                Do Until .Cells(i, "C").Value = "Vendor :"
                    
                    i = i + 1
                Loop
                supplier = .Cells(i, "D").Value
                
                Do Until IsNumeric(.Cells(i, "E").Value) And .Cells(i, "E").Value <> vbNullString
                    
                    i = i + 1
                Loop
                
                Do Until .Cells(i, "E").Value = vbNullString
                
                    nextrow = nextrow + 1
                    
                    ws.Cells(nextrow, "A").Value = "YES"
                    ws.Cells(nextrow, "B").Value = Date
                    ws.Cells(nextrow, "C").Value = "Bill"
                    ws.Cells(nextrow, "D").Value = .Cells(i, "E").Value
                    ws.Cells(nextrow, "E").Value = supplier
                    ws.Cells(nextrow, "F").Value = "Account Payable"
                    ws.Cells(nextrow, "L").Value = .Cells(i, "N").Value
                    
                    i = i + 1
                Loop
            Next i
        End With
        
        Application.ScreenUpdating = True
    End Sub

  3. #3
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    Re: VB Code to reorganize data

    Hello Bob:

    Thanks a loy.
    Please refer to attached file with the above code and result.
    It gets wrong result from Vendor #5

    Please let me know if you have any questions.
    Thanks.

    Riz
    Attached Files Attached Files

  4. #4
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Hi ! Try this ‼


    As a beginner starter :

    PHP Code: 
    Sub Demo1()
         
    Dim L&, Rg As RangeR&
             
    2
             Sheet2
    .UsedRange.Offset(1).Clear
             Application
    .ScreenUpdating False
        With Sheet1
    .UsedRange.Columns(5)
               
    Set Rg = .Find("Bill #", , xlValuesxlWhole)
            If 
    Not Rg Is Nothing Then
                    R 
    Rg.Row
                
    Do
                    
    With Rg(3).CurrentRegion
                        
    .Copy Sheet2.Cells(L4)
                         
    Sheet2.Cells(L5).Resize(.Count).Value2 Rg(00).Value2
                         Sheet2
    .Cells(L12).Resize(.Count).Value2 = .Offset(, 9).Value2
                         L 
    + .Count
                    End With
                       Set Rg 
    = .FindNext(Rg)
                
    Loop Until Rg.Row R
                       Set Rg 
    Nothing
            End 
    If
        
    End With
        With Sheet2
    .Rows("2:" 1).Columns
            
    .Item("A:C").Value = Array("YES"Date"Bill")
            .
    Item(6).Value2 "Account Payable"
            
    .Item(12).NumberFormat "#,##0.00"
        
    End With
             Application
    .ScreenUpdating True
    End Sub 
    Do you like it ? So thanks to click on bottom left star icon « Add Reputation » !

  5. #5
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    Re: VB Code to reorganize data

    Hello:

    Thanks a lot, Marc your code works

    R

+ 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. VB Code to reorganize data
    By rizmomin in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-12-2019, 09:14 AM
  2. [SOLVED] VB Code to reorganize data
    By rizmomin in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-01-2017, 04:31 PM
  3. [SOLVED] VB Code to reorganize data in a row
    By rizmomin in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-31-2016, 04:41 PM
  4. [SOLVED] VB Code to reorganize data
    By rizmomin in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-03-2016, 08:57 PM
  5. VB Code to reorganize data..
    By rizmomin in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-19-2016, 11:09 PM
  6. VB Code to reorganize data in a sheet
    By rizmomin in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-20-2016, 08:27 PM
  7. [SOLVED] VB Code to reorganize data
    By rizmomin in forum Excel Programming / VBA / Macros
    Replies: 22
    Last Post: 03-29-2016, 04:24 PM

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