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
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
My columns are dynamic.

Just checking... do you mean the number of columns is dynamic or the number of rows is dynamic?
 
Upvote 0
Also why are certain columns not filled down? Is this deliberate? If yes list the columns not to be filled down.
 
Upvote 0
Sorry for my mistakes.
Both Columns and Rows are dynamic and all the Blank rows has to be filled from values above.
 
Upvote 0
Assuming your data starts in A1. try the below...

Code:
Sub FillCell2()
    Dim lr As Long, lc As Long

    lr = Cells.Find("*", , xlValues, , xlByRows, xlPrevious).Row
    lc = Cells.Find("*", , xlValues, , xlByColumns, xlPrevious).Column

    With Range(Cells(3, "A"), Cells(lr, lc))
        .SpecialCells(xlCellTypeBlanks).FormulaR1C1 = "=IF(R[-1]C<>"""",R[-1]C,"""")"
        .Value = .Value
    End With
End Sub
 
Upvote 0
It is not working. I have tried A1 and A2 also. My data has headers and it will start in A2
i1O1MU


5xu3gk.jpg
 
Upvote 0
Works fine at my end. Are you sure that your cells are truly blank and not formulas returning "" or downloaded data with non printing characters?
By the way I can see you had headers from the first post and the code allowed for that.
 
Upvote 0
I have tried with both header on and then deleting header in both case it is not working and fills 43324. I am using excel 2016
 
Upvote 0
That number is a date either comment out the .Value line so it remains as a formula or format the date columns as dates.
Please don't remove the header row as I have already told you that the code allows for the header row... sigh
 
Upvote 0
I have formatted it to date. it copies value to Column B only. I want to copy the values from above cell for every column if its blank.
 
Upvote 0

Forum statistics

Threads
1,215,066
Messages
6,122,947
Members
449,095
Latest member
nmaske

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