Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
A3 in ActiveSheet is a formula =CONCATENATE(F3&"
"&TEXT($F$7,"DD-MMM-YY")&F2&" ZONE") The macro (courtesy of Ron de Bruin, amended for workbook,sheet and ranges only) is required to copy the contents of A3 in the ActiveSheet to the NEXT EMPTY CELL in Corporate Returns Main.xls!Sheet2 column B. Error: Copying is always done on Sheet2!B3 and not on successive cells. Could someone tell me what I am doing wrong. Sub CorporateReturnsToMain() ' ' CorporateReturnsToMain Macro ' Dim sourceRange As Range Dim destrange As Range Dim destWB As Workbook Dim Lr As Long Application.ScreenUpdating = False If bIsBookOpen("Corporate Returns Main.xls") Then Set destWB = Workbooks("Corporate Returns Main.xls") Else Set destWB = Workbooks.Open("c:\Zone1\Corporate Returns Main.xls") End If Lr = LastRow(destWB.Worksheets("Sheet2")) + 1 Set sourceRange = ThisWorkbook.ActiveSheet.Range("A3") Set destrange = destWB.Worksheets("Sheet2").Range("B" & Lr) sourceRange.Copy destrange.PasteSpecial xlPasteValues, , False, False Application.CutCopyMode = False destWB.Close True Application.ScreenUpdating = True ' End Sub ====== Function LastRow(sh As Worksheet) On Error Resume Next LastRow = sh.Cells.Find(What:="*", _ After:=sh.Range("B2"), _ Lookat:=xlPart, _ LookIn:=xlFormulas, _ SearchOrder:=xlByRows, _ SearchDirection:=xlPrevious, _ MatchCase:=False).Row On Error GoTo 0 End Function ===== Function bIsBookOpen(ByRef szBookName As String) As Boolean ' Rob Bovey On Error Resume Next bIsBookOpen = Not (Application.Workbooks(szBookName) Is Nothing) End Function Thank you -- Robert |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Copy empty cells from one workbook to another - Code | Excel Programming | |||
Copy empty cells from one workbook to another - Code | Excel Discussion (Misc queries) | |||
Copy empty cells from one workbook to another - Code | Excel Programming | |||
VBA to copy to empty cell directly below a cell when analogous cells in different column have same value as each other? | Excel Programming | |||
VBA to copy to empty cell directly below a cell when analogous cells in different column have same value as each other? | Excel Programming |