472,804 Members | 1,573 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,804 software developers and data experts.

Use a string to represent a range object

214 100+

I am trying to find out if something is possible in Excel VBA. I would like to use a string or integer to modify/represent the name of a range object. Please note that I do not have a range stored in string format.

For example, I have the following range objects already set: rng1, rng2, rng3, etc.

I am looping through rows and want to change the associated range with each iteration, using either a string or integer. Below is a sample of the code (not working) I need help with.

Expand|Select|Wrap|Line Numbers
  1. Dim loImmobile As ListObject
  2. Dim rowImmobile As ListRow
  3. Dim shtImmobile As Worksheet
  4. Dim rngPlace As Range
  5. Dim intCount As Integer
  7. Set shtImmobile = Worksheets("shtImmobile")
  8. Set loImmobile = shtImmobile.ListObjects("tblImmobile")
  9. intCount = 5
  11. For Each rowImmobile In loImmobile.ListRows
  12.         rngPlace = RandCell(Rng(intCount))
  13.        'Do things with rngPlace
  14.         intCount = intCount + 1
  15. Next rowImmobile
The problem area is in the line below. RandCell calls a function that retrieves a random cell from the given range.
Expand|Select|Wrap|Line Numbers
  1.         rngPlace = RandCell(Rng(intCount))
Thank you for your help!
Mar 31 '18 #1
2 3692
1,047 Expert 1GB
With the line below you can select all kind of range's
Expand|Select|Wrap|Line Numbers
  1. Range(Cells(row1, col1), Cells(row2, col2)).Select
With the values:
row1=2, col1=2, row2=4, col2=5,
You will select the range "B2:E5"
Apr 2 '18 #2
1,047 Expert 1GB
sorry, duplicate posting.. ;(
Apr 2 '18 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

by: Cyper Hunter | last post by:
Hi: Do you know how to change the url string of URL object? For example, I have an URL object declared as: URL myurl = new URL("http://www.cnn.com"); How to change the url string of myurl...
by: Thomas | last post by:
Hi dudes, I have a range object for text (not the one in the IE, the one for Mozilla). Now I have a function to reduce/move the range in the text to the LEFT, e.g.:...
by: miki | last post by:
Hi all, How can I cast from a string to an object? For example, suppose I have classes as employee, manager, supervisor, director,...I have a user interface that takes a person name, then...
by: GlennDoten | last post by:
I just happened to be looking through the implementation of the System.Version class in the SSCLI and one of the constructors starts like this: public Version(String version) { if ((Object)...
by: Howard Weiss | last post by:
I am writing an application which automates Excel from Managed Visual C++. I have imported the Microsoft Excel Objects COM object per KB 303871 and KB 303872. If I do this in C# or VB, the...
by: Jeffrey Bradshaw | last post by:
Is there any way to make a copy of a word.range object? I have a range in a document and I need to monkey around with it but I don't want to change the original in the document. I've tried...
by: Orit | last post by:
Hello . Please find below my questions - I hope some of the ASP.NET experts of this forum will answer to those beginner's questions : My Web site should be able to work with either SQL Server...
by: vunet | last post by:
I used DOMParser to convert a response string to XML object: DOMParser.parseFromString() In browsers where DOMParser is not supported (Safari 1-2 for my case) I cannot use DOMParser. What...
by: chethan g | last post by:
Hi, I need to select the whole Excel sheet in Range object and then need to apply "alignment" and "autofit column width". As I have many merged cells, when I attempt to autofit the column width I...
by: kirubagari | last post by:
Hi expert, Need some advise on assigning string into an object. slot = lvwLotsToSkip.ListItems.Item(i).text Dim olot As Object olot = slot rc.Init olot, Nothing, Nothing, "SkipMultipleLot"
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
by: lllomh | last post by:
How does React native implement an English player?
by: Mushico | last post by:
How to calculate date of retirement from date of birth
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.