zhileezy
06-01-2009, 03:34 PM
Hi all,
I am trying to write a macro that would name sets of cells, from column C to column BM, with the first cell in column C (top left of the range) equals 60 and last cell in column C (bottom left of the range ) equals 600. The name of each range of cells would be the cell content on column A & column B. For example, if I want to highlight C7:BM60, and A7 = "101" and B7 = "1991", I want to name the range "101-1991". Here is my macro, and I'd really appreciate it if someone can tell me why the last line doesn't work. Thanks!!!:yes:yes:yes
Sub Macro1()
Dim i As Double
Dim i2 As Double
Dim sectionname As String
i = 2
i2 = 2
For i = 2 To 4744
i = i2
Do
i = i + 1
Loop Until Worksheets("CF10").Range("c" & i) = 60
i2 = i
Do
i2 = i2 + 1
Loop Until Worksheets("CF10").Range("c" & i2) = 600
sectionname = Range("a" & i).Text & "-" & Range("b" & i).Text
ActiveWorkbook.Names.Add name:=sectionname, RefersTo:="=C" & i & ":BM" & i2, Visible:=True
Next i
End Sub
I am trying to write a macro that would name sets of cells, from column C to column BM, with the first cell in column C (top left of the range) equals 60 and last cell in column C (bottom left of the range ) equals 600. The name of each range of cells would be the cell content on column A & column B. For example, if I want to highlight C7:BM60, and A7 = "101" and B7 = "1991", I want to name the range "101-1991". Here is my macro, and I'd really appreciate it if someone can tell me why the last line doesn't work. Thanks!!!:yes:yes:yes
Sub Macro1()
Dim i As Double
Dim i2 As Double
Dim sectionname As String
i = 2
i2 = 2
For i = 2 To 4744
i = i2
Do
i = i + 1
Loop Until Worksheets("CF10").Range("c" & i) = 60
i2 = i
Do
i2 = i2 + 1
Loop Until Worksheets("CF10").Range("c" & i2) = 600
sectionname = Range("a" & i).Text & "-" & Range("b" & i).Text
ActiveWorkbook.Names.Add name:=sectionname, RefersTo:="=C" & i & ":BM" & i2, Visible:=True
Next i
End Sub