
Untitled
By: a guest on
Apr 16th, 2012 | syntax:
None | size: 1.82 KB | hits: 15 | expires: Never
copy and paste the data one excel to another excel based on column name include blank cells
Windows("iTerm Export.xls").Activate
Sheets("export(1)").Select
Cells.Find(What:="Asset", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).Activate
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Windows("iTerm metrics Report.xlsx").Activate
Sheets("Raw Data from iTerm").Select
Range("A2").Select
ActiveSheet.Paste
Sub Sample()
Dim aCell As Range
Windows("iTerm Export.xls").Activate
With Sheets("export(1)")
Set aCell = .Cells.Find(What:="Asset", LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False)
'~~> Check if "Asset is found
If Not aCell Is Nothing Then
'~~> get the lastrow of the column which has "Asset"
lastRow = .Range(Split(Cells(, aCell.Column).Address, "$")(1) & _
.Rows.Count).End(xlUp).Row
Windows("iTerm metrics Report.xlsx").Activate
.Range( _
Split(Cells(, aCell.Column).Address, "$")(1) & aCell.Row & _
":" & _
Split(Cells(, aCell.Column).Address, "$")(1) & lastRow _
).Copy _
Sheets("Raw Data from iTerm").Range("A2")
Else
MsgBox "Asset not found"
End If
End With
End Sub
Columns(4).Select
Columns("D:D").Select
Columns(ActiveCell.Column).Select
lastRow = Selection.EntireColumn.Find(What:="*", after:=Range("A1"), _
LookIn:=xlFormulas, SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious).EntireRow.Row 'Use EntireRow to take hidden rows too
Range(Selection, Cells(lastRow, Selection.Column)).Select