Offset cell addresses in a variable

ChristineJ

Well-known Member
Joined
May 18, 2009
Messages
761
Office Version
  1. 365
Platform
  1. Windows
I have a variable named addresses that returns cell addresses, such as J11, A1, B3 or M5, W16, C121, X55, F99
I'd like to add code to offset each of these cell addresses. If offset one row and one column, J11, A1, B3 would instead be K12, B2, C4. The number of rows and columns that it would offset would vary.

I had been using a function that one of the members provided for when the cell addresses string appeared as a cell value.

I'd like to get the same result for when that cell addresses string is stored in a variable. Thanks!

Code:
Function MCELL(r As Long, c As Long, rng As String) As String  
MCELL = Range(rng).Offset(r, c).Address(0, 0)
End Function

 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
CJ might your cell addresses in 'addresses' contain '$" ?
 
Upvote 0
CJ might your cell addresses in 'addresses' contain '$" ?
No, never. I already stripped out dollar signs, sheet names, etc. with previous VBA code. I am just left with the cell references separate by commas. Thanks!
 
Upvote 0
Does this help?

VBA Code:
Sub CJ()

Dim addresses As String
Dim c As Integer
Dim r As Integer
Dim n As Integer
 Dim addaray As Variant
 
'variable holding your original  addresses
addresses = "J11, A1, B3"

'split into to array
addaray = Split(addresses, ",")

'Offset values
c = 1   '<<<< Column Offset
r = 1   '<<< Row offset

'convert to offset addresses
For n = 0 To UBound(addaray)
addaray(n) = Range(addaray(n)).Offset(r, c).Address(0, 0)
Next
' re-join
addresses = Join(addaray, ",")
MsgBox "Now is " & addresses
End Sub
 
Upvote 0
Solution
Does this help?

VBA Code:
Sub CJ()

Dim addresses As String
Dim c As Integer
Dim r As Integer
Dim n As Integer
 Dim addaray As Variant
 
'variable holding your original  addresses
addresses = "J11, A1, B3"

'split into to array
addaray = Split(addresses, ",")

'Offset values
c = 1   '<<<< Column Offset
r = 1   '<<< Row offset

'convert to offset addresses
For n = 0 To UBound(addaray)
addaray(n) = Range(addaray(n)).Offset(r, c).Address(0, 0)
Next
' re-join
addresses = Join(addaray, ",")
MsgBox "Now is " & addresses
End Sub

Works PERFECTLY! Thanks so much - this is the last step in a project I am working on. You have helped me several times with it - I appreciate it! CJ
 
Upvote 0

Forum statistics

Threads
1,215,055
Messages
6,122,902
Members
449,097
Latest member
dbomb1414

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