Copy and paste values from above rows in case of blank

jatinjoshi

New Member
Joined
Feb 5, 2014
Messages
34
I want to create macro to autofill values from rows containing values from the above rows.

Sample

Bill No.Bill DateBilled Party NameGSTINSale/Purchase TypeCompany Nameled Party State NameItem NameItem MRPPriceQtyFree QuantityAmountItem Tax CategoryHSN CodeBS1 NameBS1(%)BS1 AmountBS2 NameBS2(%)BS2 AmountBS3 NameBS3(%)BS3 AmountBS4 NameBS4(%)BS4 AmountBS5 NameBS5(%)BS5(Sub Total)
NGK/C/0001/18-1902-08-2018A K DRESSES19BXVPD3024N1ZZL/GST-MULTITAXNagjiWest Bengal (19)B.S - KOOL - 6846 - 18/22 95.003.000285.0056103CGST2.5017.25SGST2.5017.25Rounded Off (+) 0.50 0 0
B.S - KOOL - 6858A - 28/32 135.003.000405.0056103 0.000.00 0.00 0.00 0 0
NGK/C/0002/18-1912-08-2018A.Fashion18ADAPT5416C1ZRL/GST-MULTITAXNagjiAssam (18)BABA SUIT - DOTS - 1271 - MLXL 100.006.000600.0056111CGST2.5038.00SGST2.5038.00 0.00 0 0
B-DENIM-Ftc Jeans-2939-32/40 460.002.000920.0056203 0.000.00 0.00 0.00 0 0

<colgroup><col><col><col><col span="2"><col><col span="2"><col span="5"><col><col><col><col><col><col><col><col><col><col><col><col><col><col><col><col><col></colgroup><tbody>
</tbody>

Final Result

Bill No.Bill DateBilled Party NameGSTINSale/Purchase TypeCompany Nameled Party State NameItem NameItem MRPPriceQtyFree QuantityAmountItem Tax CategoryHSN CodeBS1 NameBS1(%)BS1 AmountBS2 NameBS2(%)BS2 AmountBS3 NameBS3(%)BS3 AmountBS4 NameBS4(%)BS4 AmountBS5 NameBS5(%)BS5(Sub Total)
NGK/C/0001/18-1902-08-2018A K DRESSES19BXVPD3024N1ZZL/GST-MULTITAXNagjiWest Bengal (19)B.S - KOOL - 6846 - 18/22 95.003.000285.0056103CGST2.5017.25SGST2.5017.25Rounded Off (+) 0.50 0 0
NGK/C/0001/18-1902-08-2018A K DRESSES19BXVPD3024N1ZZL/GST-MULTITAXNagji B.S - KOOL - 6858A - 28/32 135.003.000405.0056103CGST2.5017.25SGST2.5017.25Rounded Off (+) 0.50 0 0
NGK/C/0002/18-1912-08-2018A.Fashion18ADAPT5416C1ZRL/GST-MULTITAXNagjiAssam (18)BABA SUIT - DOTS - 1271 - MLXL 100.006.000600.0056111CGST2.5038.00SGST2.5038.00 0.00 0 0
NGK/C/0002/18-1912-08-2018A.Fashion18ADAPT5416C1ZRL/GST-MULTITAXNagji B-DENIM-Ftc Jeans-2939-32/40 460.002.000920.0056203CGST2.5038.00SGST2.5038.00 0.00 0 0

<colgroup><col><col><col><col span="2"><col><col span="2"><col span="5"><col><col><col><col><col><col><col><col><col><col><col><col><col><col><col><col><col></colgroup><tbody>
</tbody>

My columns are dynamic.

Thanks in advance
 
Upload a copy of your workbook to www.box.com, mark it for sharing and then paste the link it provides in this thread.
 
Upvote 0

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Your cells aren't blank, they have a ' (character 32) in them.
 
Last edited:
Upvote 0
Run the macro below


Code:
Sub Trimit()
    Dim myCell As Range, myRng As Range
    
    With Application
        .DisplayAlerts = False
        .ScreenUpdating = False
        .Calculation = xlCalculationManual
    End With

    Set myRng = ActiveSheet.UsedRange
    
    With myRng
        .Replace What:=Chr(160), Replacement:=Chr(32), LookAt:=xlPart
        .Replace What:=Chr(13) & Chr(10), Replacement:=Chr(32), LookAt:=xlPart
        .Replace What:=Chr(13), Replacement:=Chr(32), LookAt:=xlPart
        .Replace What:=Chr(21), Replacement:=Chr(32), LookAt:=xlPart

        .Replace What:=Chr(8), Replacement:=Chr(32), LookAt:=xlPart
        .Replace What:=Chr(9), Replacement:=Chr(32), LookAt:=xlPart
    End With

    On Error Resume Next
    For Each myCell In Intersect(myRng, _
                               myRng.SpecialCells(xlConstants, xlTextValues))
        myCell.Value = Application.Trim(myCell.Value)
    Next myCell
    On Error GoTo 0

    With Application
        .Calculation = xlCalculationAutomatic
        .DisplayAlerts = True
        .ScreenUpdating = True
    End With
End Sub

Then run the macro from earlier.

In future when asked questions like
Are you sure that your cells are truly blank and not formulas returning "" or downloaded data with non printing characters?

that you actually checked.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,583
Messages
6,125,665
Members
449,247
Latest member
wingedshoes

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