VBA frustration

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Can someone tell me why this doesn't work? Thanks!

Sub Test()
a = Worksheets("Sheet1").Range("A7")

b = Cells.Find("Total", , xlValues).Address

Worksheets("Sheet1").Range(a, b).Select
End Sub
 
Hi
what are you trying to do?
- a contains the vALUE from cell A7 (whatever is in this cell
- b contains the address of the found cell
 
Frank,
Once again you saved the day. I think you answered my question. I need to
use the Set keyword. I'm trying to select the area between A1 and where the
value of the found cell is equal to "Total". So, if I say:

Set a=Worksheets("Sheet1").Range("A1")

that should make it work, right?
 
If you know the address of the starting cell, you can specify it literally,
i.e.

Sub Test()
b = Cells.Find("Total", , xlValues).Address
Worksheets("Sheet1").Range("A1", b).Select
End Sub

or, since the arguments to Range can be range *objects* as well as string
addresses,

Sub Test()
Set b = Cells.Find("Total", , xlValues)
With Worksheets("Sheet1")
.Range(Cells(1), b).Select
End With
End Sub

In the 2nd example, you could also use "A1" instead of Cells(1)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top