Coping formulas to next row using a macro [Solved/Closed]

- - Latest reply: CADU1947
Posts
3
Registration date
Friday December 4, 2015
Last seen
December 4, 2015
- Dec 4, 2015 at 10:30 AM
Hello,
I am trying to make a macro to copy a formula to the next row in a spreadsheet. Then paste the absolute values back into the original row. It should always go to the next row, but I can't get it to do it. Here's what I have: Any help?

Sub Macro7()
'
' Macro7 Macro
' Macro recorded 04/02/2009 by Farmland Foods, Inc.
'
' Keyboard Shortcut: Ctrl+q
'
Range("B1600:AC1600").Select
Selection.Copy

Range("B1601").Select
ActiveSheet.Paste
Range("B1600").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("B1602").Select
Application.CutCopyMode = False
End Sub
See more 

1 reply

Best answer
1
Thank you
I stay away from the macro recorder whenever possible.

Try this instead:

Dim EndRow
EndRow = Range("B65536").End(xlUp).Row

Range("B" & EndRow + 1, "AC" & EndRow + 1).Value = Range("B" & EndRow, "AC" & EndRow).Value

Say "Thank you" 1

A few words of thanks would be greatly appreciated. Add comment

CCM 4339 users have said thank you to us this month

I believe I misread your post the first time. This one will copy the formulas to the next row. Then, copy and
paste values from the copy range as you stated.


Sub PasteValues()

Dim EndRow
EndRow = Range("B65536").End(xlUp).Row

Range("B" & EndRow, "AC" & EndRow).Copy Range("B" & EndRow + 1, "AC" & EndRow + 1)
Range("B" & EndRow, "AC" & EndRow).Copy
Range("B" & EndRow, "AC" & EndRow).Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Application.CutCopyMode = False
Range("B" & EndRow).Select


End Sub
CADU1947
Posts
3
Registration date
Friday December 4, 2015
Last seen
December 4, 2015
> WutUp WutUp -
Thank you, I'll try and see what happens.
How can I apply this macro with the same instructions but that instead of getting the last row, get the last column?
rizvisa1
Posts
4475
Registration date
Thursday January 28, 2010
Status
Contributor
Last seen
January 6, 2016
914 -
you can use this function to get last/first column /row within a given range

Sample Calls :
Get last used row lastrow = getItemLocation("*", sheets("sheet1").cells)
get first used row firstrow = getItemLocation("*", sheets("sheet1").cells), true, false)
get last column firstrow = getItemLocation("*", sheets("sheet1").cells), true, true, false)
get first column firstrow = getItemLocation("*", sheets("sheet1").cells), true, false, false)

Public Function getItemLocation(sLookFor As String, _
                                rngSearch As Range, _
                                Optional bFullString As Boolean = True, _
                                Optional bLastOccurance As Boolean = True, _
                                Optional bFindRow As Boolean = True) As Long
                                   
   'find the first/last row/column  within a range for a specific string
      
   Dim Cell             As Range
   Dim iLookAt          As Integer
   Dim iSearchDir       As Integer
   Dim iSearchOdr       As Integer
         
   If (bFullString) _
   Then
      iLookAt = xlWhole
   Else
      iLookAt = xlPart
   End If
   If (bLastOccurance) _
   Then
      iSearchDir = xlPrevious
   Else
      iSearchDir = xlNext
   End If
   If Not (bFindRow) _
   Then
      iSearchOdr = xlByColumns
   Else
      iSearchOdr = xlByRows
   End If
         
   With rngSearch
      If (bLastOccurance) _
      Then
         Set Cell = .Find(sLookFor, .Cells(1, 1), xlValues, iLookAt, iSearchOdr, iSearchDir)
      Else
         Set Cell = .Find(sLookFor, .Cells(.Rows.Count, .Columns.Count), xlValues, iLookAt, iSearchOdr, iSearchDir)
      End If
   End With
         
   If Cell Is Nothing Then
      getItemLocation = 0
   ElseIf Not (bFindRow) _
   Then
      getItemLocation = Cell.Column
   Else
      getItemLocation = Cell.Row
   End If
   Set Cell = Nothing

End Function
CADU1947
Posts
3
Registration date
Friday December 4, 2015
Last seen
December 4, 2015
-
Many thanks !!!