See if link helps
http://www.rondebruin.nl/copy1.htm
VBA Noob
See if link helps
http://www.rondebruin.nl/copy1.htm
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 !!!
I am sure the code should work but because I am new to macro's, I might be missing something here.Originally Posted by VBA Noob
Here's what I want to do, I want to copy the information from Row number 1 located in the sheet called IWLog and paste the information in an empty row as Values in the sheet called Log.
Thank you.
Here's my code:
![]()
Sub Copy_1_Value_PasteSpecial() Dim SourceRange As Range, DestRange As Range Dim DestSheet As Worksheet, Lr As Long With Application .ScreenUpdating = False .EnableEvents = False End With 'fill in the Source Sheet and range Set SourceRange = Sheets("IWLog").Range("A1:Z1") 'Fill in the destination sheet and call the LastRow 'function to find the last row Set DestSheet = Sheets("Log") Lr = LastRow(DestSheet) 'With the information from the LastRow function we can 'create a destination cell Set DestRange = DestSheet.Range("A" & Lr + 1) 'Copy the source range and use PasteSpecial to paste in 'the destination cell SourceRange.Copy DestRange.PasteSpecial xlPasteValues, , False, False Application.CutCopyMode = False With Application .ScreenUpdating = True .EnableEvents = True End With End Sub
Last edited by cooh23; 11-11-2007 at 05:42 AM.
You need to read this line again
As you forgot to addImportant: The macro examples use one function or two functions that you can find in the last section of this page.
or Instead of a function you can also check one row or column to find the last cell with a value.![]()
Function LastRow(sh As Worksheet) On Error Resume Next LastRow = sh.Cells.Find(What:="*", _ After:=sh.Range("A1"), _ Lookat:=xlPart, _ LookIn:=xlFormulas, _ SearchOrder:=xlByRows, _ SearchDirection:=xlPrevious, _ MatchCase:=False).Row On Error GoTo 0 End Function
Replace this line:
With:![]()
Lr = LastRow(DestSheet)
VBA Noob![]()
Lr = DestSheet.Cells(Rows.Count, "A").End(xlUp).Row
Thank you!
It worked!
Your welcome
VBA Noob
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
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks