ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How to quickly name cells in a row using VBA? (https://www.excelbanter.com/excel-programming/410061-how-quickly-name-cells-row-using-vba.html)

Fayyaadh Ebrahim

How to quickly name cells in a row using VBA?
 
Hi

I have to name 75 cells in a row starting from cell B4. B4 will be
named dbtr1, C4 dbtr 2 and so on.

I tried using the following code but it doesn't actually put the name
of the cell in the name box (top left had corner), however it does
show up when I go to Insert - Name - Define and it refers to the
correct cell.

I'd like the name to show up in the name box when I click the little
drop down that shows you all the named ranged in the workbook.

Sub Macro1()

Dim i As Integer

For i = 1 To 75

'ActiveWorkbook.Names.Add Name:="dbtr" & i, RefersToR1C1:="=Output
Database!R4C" & i + 1
ActiveWorkbook.Names("dbtr" & i).Delete

Next i

End Sub

Fayyaadh Ebrahim

How to quickly name cells in a row using VBA?
 
Oops, ignore this part (it was commented out from previous code I had
there anyway):

ActiveWorkbook.Names("dbtr" & i).Delete

On Apr 27, 3:58 pm, Fayyaadh Ebrahim wrote:
Hi

I have to name 75 cells in a row starting from cell B4. B4 will be
named dbtr1, C4 dbtr 2 and so on.

I tried using the following code but it doesn't actually put the name
of the cell in the name box (top left had corner), however it does
show up when I go to Insert - Name - Define and it refers to the
correct cell.

I'd like the name to show up in the name box when I click the little
drop down that shows you all the named ranged in the workbook.

Sub Macro1()

Dim i As Integer

For i = 1 To 75

'ActiveWorkbook.Names.Add Name:="dbtr" & i, RefersToR1C1:="=Output
Database!R4C" & i + 1
ActiveWorkbook.Names("dbtr" & i).Delete

Next i

End Sub



Dave Peterson

How to quickly name cells in a row using VBA?
 
Option Explicit

Option Explicit
Sub testme01()
Dim i As Long
With Worksheets("Output database")
For i = 1 To 75
.Cells(4, "A").Offset(0, i).Name = "dbtr" & i
Next i
End With
End Sub

Fayyaadh Ebrahim wrote:

Hi

I have to name 75 cells in a row starting from cell B4. B4 will be
named dbtr1, C4 dbtr 2 and so on.

I tried using the following code but it doesn't actually put the name
of the cell in the name box (top left had corner), however it does
show up when I go to Insert - Name - Define and it refers to the
correct cell.

I'd like the name to show up in the name box when I click the little
drop down that shows you all the named ranged in the workbook.

Sub Macro1()

Dim i As Integer

For i = 1 To 75

'ActiveWorkbook.Names.Add Name:="dbtr" & i, RefersToR1C1:="=Output
Database!R4C" & i + 1
ActiveWorkbook.Names("dbtr" & i).Delete

Next i

End Sub


--

Dave Peterson

Ken Johnson

How to quickly name cells in a row using VBA?
 
On Apr 28, 12:05 am, Fayyaadh Ebrahim wrote:
Oops, ignore this part (it was commented out from previous code I had
there anyway):

ActiveWorkbook.Names("dbtr" & i).Delete

On Apr 27, 3:58 pm, Fayyaadh Ebrahim wrote:

Hi


I have to name 75 cells in a row starting from cell B4. B4 will be
named dbtr1, C4 dbtr 2 and so on.


I tried using the following code but it doesn't actually put the name
of the cell in the name box (top left had corner), however it does
show up when I go to Insert - Name - Define and it refers to the
correct cell.


I'd like the name to show up in the name box when I click the little
drop down that shows you all the named ranged in the workbook.


Sub Macro1()


Dim i As Integer


For i = 1 To 75


'ActiveWorkbook.Names.Add Name:="dbtr" & i, RefersToR1C1:="=Output
Database!R4C" & i + 1
ActiveWorkbook.Names("dbtr" & i).Delete


Next i


End Sub


Hi,

I used...

Sub Macro1()

Dim i As Integer

For i = 1 To 75

ActiveWorkbook.Names.Add Name:="dbtr" & i, _
RefersToR1C1:="=OutputDatabase!R4C" & i + 1


Next i

End Sub

in a workbook with a sheet named OutputDatabase and all 75 names
appeared in the Name Box drop down list.

Ken Johnson

Fayyaadh Ebrahim

How to quickly name cells in a row using VBA?
 
Hi

Thanks very much, that worked perfectly.

On Apr 27, 4:11 pm, Dave Peterson wrote:
Option Explicit

Option Explicit
Sub testme01()
Dim i As Long
With Worksheets("Output database")
For i = 1 To 75
.Cells(4, "A").Offset(0, i).Name = "dbtr" & i
Next i
End With
End Sub



Fayyaadh Ebrahim wrote:

Hi


I have to name 75 cells in a row starting from cell B4. B4 will be
named dbtr1, C4 dbtr 2 and so on.


I tried using the following code but it doesn't actually put the name
of the cell in the name box (top left had corner), however it does
show up when I go to Insert - Name - Define and it refers to the
correct cell.


I'd like the name to show up in the name box when I click the little
drop down that shows you all the named ranged in the workbook.


Sub Macro1()


Dim i As Integer


For i = 1 To 75


'ActiveWorkbook.Names.Add Name:="dbtr" & i, RefersToR1C1:="=Output
Database!R4C" & i + 1
ActiveWorkbook.Names("dbtr" & i).Delete


Next i


End Sub


--

Dave Peterson




All times are GMT +1. The time now is 06:07 PM.

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