Make a string a value from the current row, and the column a named range

RockEd

Board Regular
Joined
Aug 13, 2021
Messages
80
Office Version
  1. 365
Platform
  1. Windows
Hello,

This is a very basic question but I don't know what the answer is!

I have a the current code:

VBA Code:
With ActiveCell
        ClientName = ActiveSheet.Cells(.Row, 2)

Client_name_1.Caption = ClientName

End with

The issue I have is that I want to be able to add new columns into my spreadsheet without fear that I'm going to break the code.

In cell B1 I have named cell (the 'named range') - "Client_name_column" however this code won't run:


VBA Code:
With ActiveCell
        ClientName = ActiveSheet.Cells(.Row, "Client_name_column")

Client_name_1.Caption = ClientName

End with

Is there a way around this?

thanks
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Please in just words tell me what your overall objective is.

Here is an example of part of what you may want.
VBA Code:
Sub Client_Name()
'Modified 11/8/2022  12:36:50 PM  EST
Dim Client_Name As String
Client_Name = Sheets("Master").Range("G1").Value
MsgBox Client_Name
Application.ScreenUpdating = True
End Sub
 
Upvote 0
If B1 has the columns number or letter you could use
Excel Formula:
With ActiveCell
        ClientName = ActiveSheet.Cells(.Row, Range("Client_name_column").Value)

Client_name_1.Caption = ClientName

End With
 
Upvote 0
If B1 has the columns number or letter you could use
Excel Formula:
With ActiveCell
        ClientName = ActiveSheet.Cells(.Row, Range("Client_name_column").Value)

Client_name_1.Caption = ClientName

End With
Thank you, but B1 doesn't have the column letter or number however I've worked it out now - I just needed to use .column at the end instead of .value; like this:

Excel Formula:
With ActiveCell
        ClientName = ActiveSheet.Cells(.Row, Range("Client_name_column").column)

Client_name_1.Caption = ClientName

End With
 
Upvote 0
Solution
Glad you sorted it & thanks for letting us know.
 
Upvote 0

Forum statistics

Threads
1,214,970
Messages
6,122,514
Members
449,088
Latest member
RandomExceller01

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top