View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.misc
JMB
 
Posts: n/a
Default question on macro

One way to find the range(s). It just gives a message box with the range
address -change when you decide what you want to do with it. Note I'm using
the codenames for the worksheets (check VBA help for more info). I'm
assuming your list is on Sheet2 Column A and the headers of the imported data
is on Shee1, Row1. Hope it helps.

Sub test()
Dim x As Range
Dim FoundCell As Range

With Sheet2
For Each x In .Range("A1", _
.Cells(.Rows.Count, 1).End(xlUp))
With Sheet1.Rows("1:1")
Set FoundCell = .Find(what:=x.Value, _
after:=.Cells(1, 1), LookIn:=xlValues, _
lookat:=xlWhole, searchorder:=xlByRows, _
searchdirection:=xlNext, MatchCase:=False, _
matchbyte:=False)
If Not FoundCell Is Nothing Then
With .Parent
MsgBox .Range(FoundCell, .Cells(.Rows.Count, _
FoundCell.Column).End(xlUp)).Address
End With
Else: MsgBox "Not Found"
End If
End With
Next x
End With

End Sub


"Harry" wrote:

Hi,

I have a spreadsheet at hand that is an output from a lab computer. Until
now, I had to do some simple calculations with excel on this sheet. But in
future I want to do more. For this I need a simple (I think) solution for a
problem. But it seems I cannot find how to do that :-)

In essence it comes down to this:

-I have a workbook with two sheets.
-In sheet one is the output file (xls) from a laboratory machine. This
consists mainly of multiple colums with each a unique text header in the
top row. Each column has a variable number of cells depending on what
analysis is done by the lab machine. It can be 10 cells or 100 cells under
each header. In practice this means that sheet one can consist of anything
from 2 to 400 rows with all numbers possible in between.
-In sheet two I have a list in one column of all possible column headers
that could be found in sheet 1 (this is made up by an total output list from
the lab machine).
Note that not from every analysis, all header names are put in sheet one.
That depends on the analysis again.
So the total list on sheet two can be 200 names long while the output from
the
labmachine to sheet one could consist of e.g. only of these 20 headers with
a variable
number of cells under each header.
-I want a macro that takes every name from sheet two and checks if it is in
the current header row of sheet one. IF SO, I want the macro to select the
cells under that column header for as far the column is filled with values.
-With this selection made by the macro, I than want to perform another
action (maybe copying it to another section of the workbook or maybe give
the selected range a name - but that is something I have to look at later).

Anybody able to help?

Regards,
Harry