Thank you!
It worked!
Thank you!
It worked!
Your welcome
VBA Noob
_________________________________________
![]()
![]()
Credo Elvem ipsum etian vivere
_________________________________________
A message for cross posters
Please remember to wrap code.
Forum Rules
Please add to your signature if you found this link helpful. Excel links !!!
Another Question:
I have gotten the codes to work, but now I want to copy the info from one worksheet to another worksheet.
The codes below work but it closes the worksheet automatically rather than keeping it open.
How do I keep test2 to remain open when running the macro?![]()
Sub Copy_To_Another_Workbook() Dim SourceRange As Range Dim DestRange As Range Dim DestWB As Workbook Dim DestSh As Worksheet Dim Lr As Long With Application .ScreenUpdating = False .EnableEvents = False End With 'Change the file name (2*) and the path/file name to your file If bIsBookOpen_RB("C:\Documents and Settings\Administrator\Desktop\Reg60\Macro enabled sheets\test\test2.xls") Then Set DestWB = Workbooks("C:\Documents and Settings\Administrator\Desktop\Reg60\Macro enabled sheets\test\test2.xls") Else Set DestWB = Workbooks.Open("C:\Documents and Settings\Administrator\Desktop\Reg60\Macro enabled sheets\test\test2.xls") End If 'Change the Source Sheet and range Set SourceRange = ThisWorkbook.Sheets("test1").Range("A1:K1") 'Change the sheet name of the database workbook Set DestSh = DestWB.Worksheets("test2") Lr = LastRow(DestSh) Set DestRange = DestSh.Range("A" & Lr + 1) 'We make DestRange the same size as SourceRange and use the Value 'property to give DestRange the same values With SourceRange Set DestRange = DestRange.Resize(.Rows.Count, .Columns.Count) End With DestRange.Value = SourceRange.Value DestWB.Close savechanges:=True With Application .ScreenUpdating = True .EnableEvents = True End With End Sub
Thank you!
Remove this line
VBA Noob![]()
DestWB.Close savechanges:=True
Removing this code leaves it open but running the macro again does not save the information. It wants to open the file again and discard any changes made.Originally Posted by VBA Noob
The reason I want the test2.xls to remain open because it is going to sit on a server and the file is fairly large. So running the macro that opens it and closes it will be time consuming. But leaving it open and just keeps adding rows and saving it later will save me a lot of time.
Thank you again..
I have a feeling that the code needs to be change somewhere here:
![]()
If bIsBookOpen_RB("C:\Documents and Settings\Administrator\Desktop\Reg60\Macro enabled sheets\test\test2.xls") Then Set DestWB = Workbooks("C:\Documents and Settings\Administrator\Desktop\Reg60\Macro enabled sheets\test\test2.xls") Else Set DestWB = Workbooks.Open("C:\Documents and Settings\Administrator\Desktop\Reg60\Macro enabled sheets\test\test2.xls") End If
This should save changes
VBA Noob![]()
DestWB.Save
Wow... Thank you very much!Originally Posted by VBA Noob
This is going to save me a lot of time.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks