Changing Columns Reference Code??

stephen.smith

Board Regular
Joined
Jul 7, 2010
Messages
119
Hey guys
I am trying to change a cell reference using VBA. The reference has the column with $ before hand so, $B and I am trying to use code to change this to any other column example $K on many different cells at one time. I have tried a replace code but its not working because of the $ I think. I need to keep the $ in the reference, so is there a way to do this. Any help would be really appreciated. Below is an example of what i have tried.
Thanks
Stephen

Code:

Sub test()
On Error Resume Next
Dim c As String, d As String
c = InputBox("Enter Original Column Letter")
d = InputBox("Enter New Column Letter")
Range("A1:A100").Replace "$" & c, "$" & d
End Sub
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Using a simplier range and formula, your code worked for me. Provide us the cell content of a cell where it is not working.
 
Upvote 0
Thanks so much
My apologies the rang in my formula is B66:B391
This is the content of cell B331
='P:\IPS 201112\[Week By Week Risk Management Info.xlsx]Game Rate'!$B173
Thanks Again
Stephen
 
Upvote 0
Sorry, but with your example I do not see the problem. If you run the code

Inputbox >> B
Inputbox >> J

Would not your given formula produce:

='P:\IPS 201112\[Week By Week Risk Management Info.xlsx]Game Rate'!$J173
 
Upvote 0
What is the content of the cell, AFTER running the code?

Staying with my example, is it (?):

Rich (BB code):
='P:\IPS 201112\[Week By Week Risk Management Info.xlsx]Game Rate'!$J173
 
Upvote 0
Also Im not sure if it makes a difference or not but when I run this macro, a box appears on the screen with the letter B in it and a blank dialog box and displays ok or cancel buttons, it does the same following this with the letter L. Is this normal??
 
Upvote 0
Also just to let you know that the cell the formula is referring to is from another spreadsheet. Does this make a difference?
 
Upvote 0
Range("A1:A100")<<< In your code instructs Excel to act upon the ActiveWorkbook AND the Activesheet, nothing else.. Substitute your Full Path Reference to the appropriate WB and Sheet!!
 
Upvote 0

Forum statistics

Threads
1,224,527
Messages
6,179,334
Members
452,907
Latest member
Roland Deschain

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