Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-04-2016, 06:18 AM
npalmer610 npalmer610 is offline Help With Copy Formula Down Macro Windows 7 64bit Help With Copy Formula Down Macro Office 2010 64bit
Novice
Help With Copy Formula Down Macro
 
Join Date: Feb 2016
Posts: 5
npalmer610 is on a distinguished road
Default Help With Copy Formula Down Macro

Hello. I was able to tweak a macro that was provided on another forum to copy a formula down to the last row (based on the adjacent column). I would like to instruct the code to run on all sheets in the workbook, so long as it's not a blank sheet, without having to click through each sheet then rerun the macro. Could someone please assist me with that? Thank you!



Code:
Sub CopytoLast()
Dim LastRow As Long
Columns("F").ClearContents
LastRow = Cells(Rows.Count, "E").End(xlUp).Row
Range("F2:F" & LastRow).Formula = "=CONCATENATE(A2,"" "", D2, "" "", E2)"
End Sub
Reply With Quote
  #2  
Old 03-04-2016, 11:53 PM
cobbe cobbe is offline Help With Copy Formula Down Macro Windows 10 Help With Copy Formula Down Macro Office 2016
Novice
 
Join Date: Mar 2016
Posts: 6
cobbe is on a distinguished road
Default

Code:
Sub CopytoLast()
Dim LastRow As Long
 Columns("F").ClearContents
  LastRow = Cells(Rows.Count, "E").End(xlUp).Row
   Range("F2").Formula = "=CONCATENATE(A2,"" "", D2, "" "", E2)"
    Range("F2").AutoFill Destination:=Range("F2:F" & LastRow)
End Sub
K.r., Cobbe
Reply With Quote
  #3  
Old 03-05-2016, 01:54 AM
Philb1 Philb1 is offline Help With Copy Formula Down Macro Windows 10 Help With Copy Formula Down Macro Office 2010 32bit
Advanced Beginner
 
Join Date: Feb 2016
Location: Auckland
Posts: 43
Philb1 is on a distinguished road
Default

This will loop through the sheets and provided the worksheet isn't blank, will run your code
Cheers

Code:
Option Explicit

Sub CopytoLast()
Dim LastRow As Long, shtCount As Long, i As Long

shtCount = ThisWorkbook.Worksheets.Count

For i = 1 To shtCount
    If Not Application.WorksheetFunction.CountA(ThisWorkbook.Sheets(i).Cells) = 0 Then
        Columns("F").ClearContents
        LastRow = Cells(Rows.Count, "E").End(xlUp).Row
        Range("F2:F" & LastRow).Formula = "=CONCATENATE(A2,"" "", D2, "" "", E2)"
    End If
Next i

Exit Sub
End Sub
Reply With Quote
  #4  
Old 03-14-2016, 07:32 AM
npalmer610 npalmer610 is offline Help With Copy Formula Down Macro Windows 7 64bit Help With Copy Formula Down Macro Office 2010 64bit
Novice
Help With Copy Formula Down Macro
 
Join Date: Feb 2016
Posts: 5
npalmer610 is on a distinguished road
Default

Quote:
Originally Posted by Philb1 View Post
This will loop through the sheets and provided the worksheet isn't blank, will run your code
Cheers

Code:
Option Explicit

Sub CopytoLast()
Dim LastRow As Long, shtCount As Long, i As Long

shtCount = ThisWorkbook.Worksheets.Count

For i = 1 To shtCount
    If Not Application.WorksheetFunction.CountA(ThisWorkbook.Sheets(i).Cells) = 0 Then
        Columns("F").ClearContents
        LastRow = Cells(Rows.Count, "E").End(xlUp).Row
        Range("F2:F" & LastRow).Formula = "=CONCATENATE(A2,"" "", D2, "" "", E2)"
    End If
Next i

Exit Sub
End Sub

Worked perfectly ... thank you!
Reply With Quote
  #5  
Old 03-14-2016, 01:15 PM
Philb1 Philb1 is offline Help With Copy Formula Down Macro Windows 10 Help With Copy Formula Down Macro Office 2010 32bit
Advanced Beginner
 
Join Date: Feb 2016
Location: Auckland
Posts: 43
Philb1 is on a distinguished road
Default

That's good
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
a macro that can copy data from copy.xls to our current excel macro.xls based on criteria: udhaya Excel Programming 1 11-12-2015 10:12 AM
Help With Copy Formula Down Macro Question about Index match formula to copy all of cells in row dmcg9760 Excel 1 11-08-2015 01:41 AM
Macro to copy formula from one cell to another anwar Excel Programming 1 04-25-2014 08:27 PM
Help With Copy Formula Down Macro Use formula to copy cell formats also mike_abc Excel 10 12-10-2011 01:55 AM
Excel copy formula KMS Excel 1 08-16-2011 03:02 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 05:42 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft