View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Matt S Matt S is offline
external usenet poster
 
Posts: 112
Default Any way to pretty this up?

ok, I tried one more thing and this seemed to work. Is there a way to make
it less condensed? For example... how come the following doesn't work?
Sheets("Engine Data").Cells.Find(What:="[Hertz]").Activate

Sheets("Engine Data").Select
Cells.Find(What:="[Hertz]").Activate
ActiveCell.Range("A2",
Range("A2").End(xlToRight)).Find(What:="FG_HC").Ac tivate
Range(Selection, Selection.End(xlDown)).Copy
Destination:=Sheets("MFCs").Range("F10")
ActiveWorkbook.Names.Add Name:="FG_HC",
RefersTo:=Sheets("MFCs").Range("F10:F" & Sheets("MFCs").Cells(Rows.Count,
"E").End(xlUp).Row)


Thanks again!
Matt


"Gary Keramidas" wrote:

maybe something like this, but you don't give enough information to actually
complete the code, (like where you discern the lastrow from). but have a look
and maybe you can complete it on your own:


Option Explicit
Sub test()
Dim arr As Variant
Dim rngfound As Range
Dim itmfound As Range
Dim i As Long
Dim lastrow As Long
arr = Array("FG_HC", "CO", "HC", "NO")

With Sheets("Engine Data")
Set rngfound = .Cells.Find(What:="[Hertz]", After:=ActiveCell,
LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:=False, _
SearchFormat:=False)

If Not rngfound Is Nothing Then
For i = LBound(arr) To UBound(arr)
With .Range(rngfound.Address,
..Range(rngfound.Address).End(xlToRight))

Set itmfound = .Find(What:=arr(i),
After:=ActiveCell, _
LookIn:=xlFormulas, LookAt:=xlPart,
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False, _
SearchFormat:=False).Activate
End With
.Range(rngfound.Address,
..Range(rngfound.Address).End(xlToRight)).Copy
Sheets("MFCs").Range("F10").PasteSpecial xlPasteAll
ActiveWorkbook.Names.Add Name:="FG_HC",
RefersToR1C1:="=MFCs!R13C6:R" & _
lastrow & "C"
Next
End If
End With
End Sub
--


Gary Keramidas
Excel 2003


"Matt S" wrote in message
...
I am trying to copy data from "Engine Data" and paste it into a new sheet.
Engine Data contains many columns of FG_HC... I only want the one under the
[Hertz] heading. The format of the Engine Data looks like the following:

[Mode]
FG_NOX FG_HC FG_CO
data data data

[Hertz]
FG_NOX FG_HC FG_CO
data data data

etc


Here is my code:

Sheets("Engine Data").Select
Cells.Find(What:="[Hertz]", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
ActiveCell.Range("A2", Range("A2").End(xlToRight)).Select
Selection.Find(What:="FG_HC", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
ActiveCell.Select
Range(Selection, Selection.End(xlDown)).Copy
Sheets("MFCs").Select
Range("F10").Select
ActiveSheet.Paste
ActiveWorkbook.Names.Add Name:="FG_HC", RefersToR1C1:="=MFCs!R13C6:R" &
LastRow & "C"


It's not pretty and I have to do this 11 times with different FG species.
(CO, HC, NO, etc.)

Any help would be appreciated!
Thanks,
Matt


.