View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
Rick[_19_] Rick[_19_] is offline
external usenet poster
 
Posts: 52
Default Too Basic A Question

There's a lot of different ways to approach this. You
should find a large variety of responses. For me, my
approach has been to use the Cells Method. A lot of
programmers work with the ranges.

For example, this is my style:

Sub Sample()
Dim S1 As Worksheet
Dim i As Integer

Set S1 = Sheets(1)

For i = 1 To 100
If S1.Cells(i, 5).Value = "Sample" Then
MsgBox "The word Sample was found at row " & _
S1.Cells(i, 5).Row & ".", , "Sample Message"
End If
Next i

End Sub

The integer "i" represents the rows, looping from 1 to
100. The integer "5" is the fifth column. You could loop
through the columns too, if you wanted. You set objects,
not variables. The sheets are objects; that's why I could
set it, the way it's written above. "Sheet(1)" is the
first sheet in the workbook.

Now, as you learn to loop through the cells or sheets
looking for conditions, you can loop within the loops,
going up and down, left and right - all sorts of things
that you can dream up of doing.

When you delete rows, you'll want to start at the bottom
and then loop up. Someone told me about that technique
many years ago. I can help you with that, if you are
interested. Let's see, first, what others might provide
for you.

I hope that gets you started.

-----Original 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
.