Using cell value as a variable for column value

ChristineJ

Well-known Member
Joined
May 18, 2009
Messages
761
Office Version
  1. 365
Platform
  1. Windows
This excerpt of code works to define two ranges of columns.
Rich (BB code):
Call SplitAny(Range("D:R,FZ:GK"), Range("68:205,542:795"), Range("D68"), Range("FZ566"))

This excerpt of code works to replace the "D" with the value in cell ED33.

Rich (BB code):
Call SplitAny(Range(Range("ED33").Value & ":Z,FZ:GK"), Range("68:205"), Range("D68"), Range("FZ566"))

I also now want to replace the "R", "FZ", and "GK" in the first line of code with the cell values in ED34, ED35, and ED36, respectively.

I am trying the following, but getting syntax errors.

Rich (BB code):
Call SplitAny(Range(Range("ED33").Value:Range("ED34").Value,Range("ED35").Value:Range("ED36").Value), Range("68:205"), Range("D68"), Range("FZ566"))

How do I need to tweak this? Thanks.
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
try:
Code:
Call SplitAny(Range(Range("ED33").Value & ":" & Range("ED34").Value & "," & Range("ED35").Value & ":" & Range("ED36").Value & ""), Range("68:205"), Range("D68"), Range("FZ566"))
(Bear in mind that your second code snippet:
Code:
Call SplitAny(Range([COLOR=#ff0000]Range("ED33").Value [/COLOR]& ":Z,FZ:GK"), Range("68:205"), Range("D68"), Range("FZ566"))
is not equivalent to your first:
Code:
Call SplitAny(Range("[COLOR=#ff0000]D:R,FZ:GK[/COLOR]"), Range("68:205[B][COLOR=#0000ff],542:795[/COLOR][/B]"), Range("D68"), Range("FZ566"))
since it misses out the blue highlighted bit.)
 
Upvote 0
Wonderful! It works perfectly.

I was playing with the row ranges as well and did not post identical versions of that part. But that is all OK now.

Appreciate the quick response. This really helps!
 
Upvote 0
Christine

Out of curiousity, what does the SplitAny function/sub do?
 
Upvote 0
It is part of code that splits the screen into two screens that both have scrollbars and hides all of the cells where I have content. The SplitAny sub then unhides the cells that are to appear in the left and the right screen and properly positions them.
 
Upvote 0

Forum statistics

Threads
1,214,535
Messages
6,120,093
Members
448,944
Latest member
SarahSomethingExcel100

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