View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default Too Basic A Question

Set rng = Range(cells(1,1),Cells(rows.count,1).End(xlup))

would set a reference to all the data in Column A (the second value in
Cells) of the active sheet.

To work on another sheet that is not the active sheet

With Worksheets("Sheet9")
Set rng = .Range(.cells(1,1),.Cells(rows.count,1).End(xlup))
End with

Now to loop through each cell

Dim rng as Range, rng1 as Range
Dim cell as Range
With Worksheets("Sheet9")
Set rng = .Range(.cells(1,1),.Cells(rows.count,1).End(xlup))
End with

for each cell in rng
if cell.Value = 3 then
if rng1 is nothing then
set rng1 = cell
else
set rng1 = Union(rng1,cell)
end if
Next
if not rng1 is nothing then
rng1.EntireRow.copy Destination:= _
Worksheets("Sheet3").Range("A1")
rng1.EntireRow.ClearContents
' or
' rng1.Entirerow.Delete
End if

If you read some of the posting in this newgroup, you will get good sample
code on how to do a variety of actions in Excel.

Dave McRitchie has some links to Tutorials on Excel and VBA:

http://www.mvps.org/dmcritchie/excel....htm#tutorials

the vba tutorials are after the excel tutorials

Other sources

Chip Pearson's site:
http://www.cpearson.com/excel.htm
look at the pages/topics indexes.

See John Walkenbach's site
http://www.j-walk.com/ss/excel

go to the developer's tips.

--
Regards,
Tom Ogilvy


dave wrote in message
...
I've been a programmer for many years. I can do the
programming if I can figure out how to get at the data.
That's my problem with using VBA with Excel (or Word,
etc.) How do I find out how to access a cell, group of
cells, range, worksheet, etc. using VBA.

For example, I have a worksheet that has rows of data. I
would like to search a column for a particular value and
if it is present, delete the data and row from the
current worksheet and paste it into another sheet. I can
figure out how to search for the data by recording a
macro when I do it manually. But when I then select the
row to so I can do a Ctrl-X to "move" the data, the
recorded macro does a .Select on that specific row. I
need to be able to have the selected row number put into
a variable that I can use to "cut" the data then when I
go to the target sheet I need to have the target row
incremented. Then I want to go back to the source sheet,
delete the row and repeat process until the search is no
longer successful.
How do I do those kind of things? I'm not real familiar
with the data setup that allows me access to the features
I need.

Thanks for any and all help,

dave