VBA Help creating/renaming new rows with specific information based on exported data

wings516

New Member
Joined
Sep 6, 2014
Messages
3
I'm currently trying to utilize the below VBA code I found here to take a spreadsheet export from my software and break it up into a usable form for my projects. As is, the data itself is all in a single row. I need this data to be broken up into a "Material" and "Labor" row separate from each other. That being said, I have toiled with VBA once before, and quite a while ago.

Currently, the only data I need is from Columns B, C, and D. I then need the current row in column A to be renamed, and a new row inserted below it with a generated name based on its predecessor (Rename row1 column A Material, Insert new row(2) column A and name Labor)

Code:
Public Sub ShiftData()

    'Declarations
    Dim wsData As Worksheet
    
    Dim rngCopy As Range
    
    Dim i As Long               'Loop variable
    Dim j As Long               'Loop variable
    
    Dim lngFirstDataRow As Long
    Dim lngLastDataRow As Long
    
    Dim boolDataFound As Boolean    'True or false value
    
    
    'Initialization
    Set wsData = ActiveSheet
    lngFirstDataRow = 21         'Replace with your own value - row where the data starts
    lngLastDataRow = 32        'Replace with your own value - row where the data ends
    
    
    'Loop from the bottom to top.  Why?  Because when we insert
    'rows, it will shift stuff down.
    For i = lngLastDataRow To lngFirstDataRow Step -1
    
        'Check columns AL - AP for data
        boolDataFound = False
        For j = 4 To 6        'AL is the 38th column, AP the 42nd
            
            'If it's not blank...
            If Not wsData.Cells(i, j).Text = "" Then
                
                '...then there is data.  Change the boolean to TRUE and exit the for loop
                boolDataFound = True
                Exit For
            End If
        Next j
        
        'If we found data there
        If boolDataFound Then
        
            'Insert a new row below the current row
            wsData.Rows(i + 1).Insert shift:=xlShiftDown
            
            'Copy the data
            Set rngCopy = wsData.Range(wsData.Cells(i, 4), wsData.Cells(i, 6))
            rngCopy.Copy
            
            'Copy that data into cells AB-AF
            wsData.Cells(i + 1, 4).PasteSpecial xlPasteAll
            
            'Copy the value in column B
            wsData.Cells(i + 1, 6).Value = wdata.Cells(i, 6).Value
            
        End If


    Next i
    
    'Remove the copy mode
    Application.CutCopyMode = False
    
End Sub

Here is a sample of the data in export format.
pommVGc

pommVGc.png


I would need to grab data from columns...
A - for row name/floor reference
M - Material Amount
R - Labor Amount

Here is a sample of the data in my desired format.
wZrp6vV.png


Floor row is created
Single row is split into two, renamed and material/labor specific data copied into cells
Material - Column D
Labor - Column B

I appreciate any support/direction you guys have to offer. While this is a small example that doesn't warrant a VBA macro, I typically have around 100-500 rows of information on a typical job to reorganize 3 to 4 times a week.
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.

Forum statistics

Threads
1,216,095
Messages
6,128,790
Members
449,468
Latest member
AGreen17

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