+ Reply to Thread
Results 1 to 10 of 10

VB Code to clean up Payroll Data by deleting rows

Hybrid View

rmomin VB Code to clean up Payroll... 01-04-2022, 07:01 PM
Trebor76 Re: VB Code to clean up... 01-04-2022, 08:36 PM
Sintek Re: VB Code to clean up... 01-05-2022, 02:04 AM
rmomin Re: VB Code to clean up... 01-05-2022, 08:33 AM
Sintek Re: VB Code to clean up... 01-05-2022, 01:56 PM
rmomin Re: VB Code to clean up... 01-06-2022, 07:00 AM
rmomin Re: VB Code to clean up... 01-06-2022, 04:51 PM
Trebor76 Re: VB Code to clean up... 01-06-2022, 08:40 PM
rmomin Re: VB Code to clean up... 01-06-2022, 10:42 PM
Sintek Re: VB Code to clean up... 01-07-2022, 08:00 AM
  1. #1
    Forum Contributor
    Join Date
    01-31-2012
    Location
    Georgia
    MS-Off Ver
    Excel 2010
    Posts
    194

    VB Code to clean up Payroll Data by deleting rows

    Hello:

    Please refer to attached file.
    I have data as shown in Sheet1 and it needs to be transformed as shown in Sheet2

    Basically, need VB code to look for ", in Column B,\
    if Found then copy Data from next row column C into Column C above arow

    In this case I would copy Cell C3 to Cell C2
    So now you have B2 = Name of employee, C2= Amount $2500 and D2 = 03/31/20

    And this needs to go thru the whole sheet and delete the rows in between

    I have shown completed manually in Sheet2.

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

    R




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

  2. #2
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,565

    Re: VB Code to clean up Payroll Data by deleting rows

    Hi rmomin,

    Here's one way:

    Option Explicit
    Sub Macro1()
        
        Dim wsSrc As Worksheet, wsDestin As Worksheet
        Dim i As Long, j As Long
        
        Application.ScreenUpdating = False
        
        Set wsSrc = Sheets("Sheet1")
        Set wsDestin = Sheets("Sheet2")
        
        For i = 2 To wsSrc.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
            If StrConv(wsSrc.Range("A" & i), vbProperCase) = "Salary" Then
                j = IIf(j = 0, 2, j + 1)
                wsDestin.Range("A" & j).Value = wsSrc.Range("A" & i - 1)
                wsDestin.Range("B" & j).Value = wsSrc.Range("B" & i - 1)
                wsDestin.Range("C" & j).Value2 = wsSrc.Range("C" & i).Value2
                wsDestin.Range("D" & j).Value = wsSrc.Range("D" & i - 1)
            End If
        Next i
        
        Application.ScreenUpdating = True
    
    End Sub
    Regards,

    Robert
    ____________________________________________
    Please ensure you mark your thread as Solved once it is. Click here to see how
    If this post helps, please don't forget to say thanks by clicking the star icon in the bottom left-hand corner of my post

  3. #3
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: VB Code to clean up Payroll Data by deleting rows

    Another Option...
    Sub J3v16()
    With Range("A2:D" & Cells(Rows.Count, 4).End(xlUp).Row)
        With .Columns(3).SpecialCells(xlCellTypeBlanks): .FormulaR1C1 = "=R[1]C": .Value = .Value: End With
        With .Columns(4): .Replace "Amount", "": .SpecialCells(xlCellTypeConstants, xlNumbers).Clear: .SpecialCells(xlCellTypeBlanks).EntireRow.Delete: End With
    End With
    End Sub
    Last edited by Sintek; 01-05-2022 at 02:10 AM.
    Good Luck...
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the [★ Add Reputation] to left of post window...
    Also....Add a comment if you like!!!!
    And remember...Mark Thread as Solved...
    Excel Forum Rocks!!!

  4. #4
    Forum Contributor
    Join Date
    01-31-2012
    Location
    Georgia
    MS-Off Ver
    Excel 2010
    Posts
    194

    Re: VB Code to clean up Payroll Data by deleting rows

    Hello

    Thanks to both, it works

    R

  5. #5
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: VB Code to clean up Payroll Data by deleting rows

    Glad I could contribute...

  6. #6
    Forum Contributor
    Join Date
    01-31-2012
    Location
    Georgia
    MS-Off Ver
    Excel 2010
    Posts
    194

    Re: VB Code to clean up Payroll Data by deleting rows

    Hello Guys:

    Hello:

    Looks like I will need help in changing previosly done macro as it is malfunctioning.

    Please refer to attached file.

    Here Look for character "," in column D.
    If Found then the value in 1 row below to the row with the "," and then copy the whole row in Sheet2


    Let me know if you have any questions.
    Thanks.

    R
    Attached Files Attached Files

  7. #7
    Forum Contributor
    Join Date
    01-31-2012
    Location
    Georgia
    MS-Off Ver
    Excel 2010
    Posts
    194

    Re: VB Code to clean up Payroll Data by deleting rows

    Hello Trebor or sintek

    Or any other exceler, can you help.

    Thanks

    R

  8. #8
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,565

    Re: VB Code to clean up Payroll Data by deleting rows

    Looks like I will need help in changing previosly done macro as it is malfunctioning.
    It's not that the codes are malfunctioning but your requirement (data layout) has changed

    See how this goes:

    Option Explicit
    Sub Macro2()
        
        Dim wsSrc As Worksheet, wsDestin As Worksheet
        Dim i As Long, j As Long
        
        Application.ScreenUpdating = False
        
        Set wsSrc = Sheets("Sheet1")
        Set wsDestin = Sheets("Sheet2")
        
        For i = 2 To wsSrc.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
            If InStr(wsSrc.Range("D" & i), ",") > 0 Then
                j = IIf(j = 0, 2, j + 1)
                wsDestin.Range("A" & j).Value = wsSrc.Range("A" & i)
                wsDestin.Range("D" & j).Value = wsSrc.Range("D" & i)
                wsDestin.Range("G" & j).Value2 = wsSrc.Range("G" & i + 1).Value2
                wsDestin.Range("M" & j).Value = wsSrc.Range("M" & i)
                wsDestin.Range("P" & j).Value = wsSrc.Range("P" & i)
            End If
        Next i
        
        Application.ScreenUpdating = True
    
    End Sub

  9. #9
    Forum Contributor
    Join Date
    01-31-2012
    Location
    Georgia
    MS-Off Ver
    Excel 2010
    Posts
    194

    Re: VB Code to clean up Payroll Data by deleting rows

    Hello Trebor

    Thanks a lot, if any thing change i will let you know.

    R

  10. #10
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: VB Code to clean up Payroll Data by deleting rows

    As Trebor says...Complete different data setup...
    Sub J3v16()
    With Range("A1:P" & Cells(Rows.Count, 1).End(xlUp).Row)
        Union(.Columns(7), .Columns(16)).NumberFormat = "General"
        With .Columns(7).SpecialCells(xlCellTypeBlanks): .FormulaR1C1 = "=R[1]C": End With
        With .Columns(7).CurrentRegion: .Value = .Value: End With
        With .Columns(3): .SpecialCells(xlCellTypeConstants).EntireRow.Delete: End With
        With .Columns(4): .SpecialCells(xlCellTypeBlanks).EntireRow.Delete: End With
    End With
    End Sub
    Last edited by Sintek; 01-08-2022 at 10:52 AM.

+ 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. [SOLVED] VB Code to clean up data which has Merged Data by deleting blank rows & Columns
    By rizmomin in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-21-2019, 01:06 PM
  2. Cleaning rows of data and clean rows of duplicates not deleting.
    By guidom in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-21-2014, 12:48 PM
  3. VBA Code to Clean up Rows
    By tmarcello935 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-25-2013, 03:15 PM
  4. [SOLVED] VBA code for deleting Rows that contain specific criteria from Filtered Data
    By carlosriver24 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-31-2012, 12:23 PM
  5. i need vba code for deleting rows in excel based on different sheets data
    By Rajagopalan in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-25-2012, 10:28 AM
  6. [SOLVED] VBA Code to optimize and clean data- clean out numerical/ or symbol
    By tracylsr in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-05-2012, 04:21 PM
  7. [SOLVED] VBA Code to optimize and clean data
    By JoaoVr in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-29-2012, 10:33 AM

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