macro to copy formulas from last row of data to same columns in first empty row

boxxcar

New Member
Joined
Apr 16, 2020
Messages
20
Platform
  1. Windows
I am a Novice. I am unable to use a variables in cell addresses successfully. Here is my fake code. Thanks for any help you provide.

Sub Macro1()


Dim Rx As Long 'for Row
Dim Cx As Long 'for Col
Dim iRow As Long 'for last row with data
Dim x As Integer

Set ws = Worksheets("Ebay Inventory")

'for columns B, D, I, K, L in last row with data
'copy down formulas in first empty row

'find first empty row in database and assign it to var iRow
iRow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, _
SearchDirection:=xlPrevious, LookIn:=xlValues).iRow + 1

For x = 1 To 5

If x = 1 Then Cx = 2 'Column #
If x = 2 Then Cx = 4
If x = 3 Then Cx = 9
If x = 4 Then Cx = 11
If x = 5 Then Cx = 12

Cells(iRow + 1, Cx).Copy Cells(iRow + 1, Cx)
Next x

End
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
If you are copying the last cell then you don't want the +1 at the end of
VBA Code:
iRow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, _
          SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1
(or later in the code), try...
VBA Code:
Sub Macro1()


    Dim Rx As Long                               'for Row
    Dim Cx As Long                               'for Col
    Dim iRow As Long                             'for last row with data
    Dim x As Integer
    Dim ws As Worksheet
    Set ws = Worksheets("Ebay Inventory")

    'for columns B, D, I, K, L in last row with data
    'copy down formulas in first empty row

    'find first empty row in database and assign it to var iRow
    iRow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, _
                         SearchDirection:=xlPrevious, LookIn:=xlValues).Row

    For x = 1 To 5

        If x = 1 Then Cx = 2                     'Column #
        If x = 2 Then Cx = 4
        If x = 3 Then Cx = 9
        If x = 4 Then Cx = 11
        If x = 5 Then Cx = 12

        ws.Cells(iRow, Cx).Copy ws.Cells(iRow + 1, Cx)
      ' or Range(ws.cells(irow,Cx),ws.cells(irow+1,Cx)).filldown
    Next x

    End Sub
 
Upvote 0
Dead on!! Thanks. I just could not figure out the syntax to write the formulas (i.e. formulae, Eng. Maj HA). I take consulation that I was pretty close. Thanks for your time and you instruction.
 
Upvote 0
Happy it helped and welcome to the board.
 
Upvote 0

Forum statistics

Threads
1,214,584
Messages
6,120,387
Members
448,956
Latest member
JPav

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