How to shift numbers down a column using a formula

dbcooper88

New Member
Joined
Dec 3, 2016
Messages
36
I would like to shift the numbers in column B down where there is an empty cell with the result being column C. If possible I would then like to put results of C in an array formula in column D {=A1:A10*C1:C10)} maintaining the corresponding empty cells. Formulas would therefore begin in C1 and D1. Thanks.


A
B
C
D
1
33
2
38
3
34
33
99.00
4
38
152.00
5
37
34
170.00
6
59
37
222.00
7
58
59
413.00
8
57
58
464.00
9
57
513.00
10
68
68
680.00

<tbody>
</tbody>
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Give this macro a try...
Code:
Sub ShiftDownAndAddFormula()
  Dim LastRow As Long, BlankCount As Long
  LastRow = Cells(Rows.Count, "B").End(xlUp).Row
  With Range("B1:B" & LastRow)
    .Offset(, 1) = .Cells.Value
    BlankCount = Application.CountBlank(.Cells)
    .Offset(, 1).SpecialCells(xlBlanks).Delete xlShiftUp
    .Offset(BlankCount, 1) = .Offset(, 1).Value
  End With
  Range("C1:C" & BlankCount).ClearContents
  With Range("D1:D" & LastRow)
    .Formula = "=IF(C1="""","""",A1*C1)"
    .NumberFormat = "0.00"
  End With
End Sub

HOW TO INSTALL MACROs
------------------------------------
If you are new to macros, they are easy to install and use. To install it, simply press ALT+F11 to go into the VB editor and, once there, click Insert/Module on its menu bar, then copy/paste the above code into the code window that just opened up. That's it.... you are done. To use the macro, go back to the worksheet with your data on it and press ALT+F8, select the macro name (ShiftDownAndAddFormula) from the list that appears and click the Run button. The macro will execute and perform the action(s) you asked for. If you will need to do this again in this same workbook, and if you are using XL2007 or above, make sure you save your file as an "Excel Macro-Enabled Workbook (*.xlsm) and answer the "do you want to enable macros" question as "Yes" or "OK" (depending on the button label for your version of Excel) the next time you open your workbook.
 
Upvote 0

Forum statistics

Threads
1,224,821
Messages
6,181,163
Members
453,021
Latest member
Justyna P

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