View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default Referencing Cells in VB

I assume there will be multiple cells with B11 for example. If the system is
identified only by the first character being B and could have any two
numbers after, then you will have to modify your equality test to only look
at the first character

If left(System,1) = Left(ActualSystem,1) Then


Private Sub CommandButton2_Click()
'Creating Report Number One
t = 1

System = Sheets("input").Range("E3").Value
Do While t < 10
ActualSystem = Sheets("electrical").Range("At")(t).Value

If System = ActualSystem Then
Sheets("electrical").Range("At")(t).Copy Destination:= _
Sheets("report").Cells(Rows.Count, 1).End(x1Up) _
.Offset(1, 0)
End If
t = t + 1
Loop
End Sub

--
Regards,
Tom Ogilvy


"Brian McGuire" wrote in message
...
I am attempting to write a macro that will pull information from a

spreadsheet into a list on another sheet. For instance, I have many pieces
of equipment and want to see only the equipment for a certain system, so I
type in the system I want, hit my button, and go. I am running into problems
with searching to the next cell in the spreadsheet. This is the code I have
so far

Private Sub CommandButton2_Click()
'Creating Report Number One
t = 1
System = Sheets("input").Range("E3")
Do While t < 10
ActualSystem = Sheets("electrical").Range("At")

If System = ActualSystem Then
Sheets("electrical").Range("At").Copy Destination:= _
Sheets("report").Cells(Rows.Count, 1).End(x1Up) _
.Offset(1, 0)
t = t + 1
Else
t = t + 1

End If
Loop
End Sub

I want it to put only the pieces of equipment for that particular system

on the list, and I want to have it where there are no blank spaces between
the pieces of equipment on the list. The system is numbered like this:

"Bxx"

with xx being any integers. I know I am referencing the cells wrong in

Excel, I know you just cant say Cell (At) and have t be counted each time
through, which is the problem I am running into, it gives me a runtime error
whenever it gets to the ActualSystem variable. Any help on this matter would
be greatly appreciated. Thanks.

Brian