View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.misc
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default defining names in a macro

Worksheets("Sheet1").Range("duplex") is a whole column?

If it is, then things like this:
If myRangeD.Text = "X"
aren't valid.

With multiple cells, the .text property will return Null.
You could use .Text to refer to what's displayed in a single cell, though.

If you used:
If myRangeD.Value = "X"
you'd have a different problem.

For multiple cells, .value returns an 2 dimensional array (x rows by y
columns). And you can't compare an array to that single value. (You could
compare a single element of that array to a single value, though.)



guidop12 wrote:

With the below coding and example of my spreadsheet

Dim myRangeD As Range, myRangeF As Range, myRangeC As Range, myRangeE As
Range, _
myRangeH As Range, myRangeG As Range
Worksheets("sheet1").Activate
Set myRangeD = Worksheets("Sheet1").Range("duplex")
Set myRangeF = Worksheets("Sheet1").Range("color")
Set myRangeC = Worksheets("Sheet1").Range("simplex")
Set myRangeE = Worksheets("sheet1").Range("b_w")
Set myRangeH = Worksheets("Sheet1").Range("price")
Set myRangeG = Worksheets("Sheet1").Range("of_sheets")

If myRangeD.Text = "X" And myRangeF.Text = "X" Then
myRangeH = (myRangeG * 2 * 0.045)
End If
If myRangeC.Text = "X" And myRangeF.Text = "X" Then
myRangeH = (myRangeG * 1 * 0.045)
End If
If myRangeD.Text = "X" And myRangeE.Text = "X" Then
myRangeH = (myRangeG * 2 * 0.008)
End If
If myRangeC.Text = "X" And myRangeE.Text = "X" Then
myRangeH = (myRangeG * 1 * 0.008)
End If
End Sub

Job Machine Simplex Duplex B/W Color # of Sheets Price

79815 6500 X X 2965 $237.20

79700 C500 X X 420 $37.80

79718 6500 X X 25 $0.10

Each column has a defined name which highlights the whole column.
My question is why does my macro only work if I change this line to be
Set myRangeD = Worksheets("Sheet1").Range("D3") and not the name


--

Dave Peterson