ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   VBA frustration (https://www.excelbanter.com/excel-programming/314645-vba-frustration.html)

Mark1

VBA frustration
 
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

Frank Kabel

VBA frustration
 
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

--
Regards
Frank Kabel
Frankfurt, Germany


Mark1 wrote:
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


Mark1

VBA frustration
 
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?

"Frank Kabel" wrote:

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

--
Regards
Frank Kabel
Frankfurt, Germany


Mark1 wrote:
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



Myrna Larson

VBA frustration
 
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)

On Mon, 25 Oct 2004 11:34:23 -0700, "Mark1"
wrote:

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?

"Frank Kabel" wrote:

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

--
Regards
Frank Kabel
Frankfurt, Germany


Mark1 wrote:
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




Frank Kabel

VBA frustration
 
Hi
yes it should

--
Regards
Frank Kabel
Frankfurt, Germany


Mark1 wrote:
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?

"Frank Kabel" wrote:

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

--
Regards
Frank Kabel
Frankfurt, Germany


Mark1 wrote:
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




All times are GMT +1. The time now is 10:02 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com