473,545 Members | 1,995 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Use a string to represent a range object

gnawoncents
214 New Member
Greetings,

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
  6.  
  7. Set shtImmobile = Worksheets("shtImmobile")
  8. Set loImmobile = shtImmobile.ListObjects("tblImmobile")
  9. intCount = 5
  10.  
  11. For Each rowImmobile In loImmobile.ListRows
  12.         rngPlace = RandCell(Rng(intCount))
  13.        'Do things with rngPlace
  14.         intCount = intCount + 1
  15. Next rowImmobile
  16.  
  17.  
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))
  2.  
Thank you for your help!
Mar 31 '18 #1
2 3938
Luuk
1,047 Recognized Expert Top Contributor
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
Luuk
1,047 Recognized Expert Top Contributor
sorry, duplicate posting.. ;(
Apr 2 '18 #3

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

Similar topics

1
8664
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 to be "http://www.yahoo.com"? Thanks.
1
4795
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.: range.setStart(range.startContainer, startPos-1); range.setEnd(range.endContainer, endPos-1); range ist the range object created via window.getSelection.getRangeAt(0). Now I...
5
2346
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 performs query database and returns a string which tells that person is either employee, manager,...If it's student, a student object will be return. I...
8
4097
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) version == null) throw new ArgumentNullException("version"); Does anyone have any ideas why the string parameter is being cast to an object prior to...
0
983
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 ObjectBrowser provides interfaces for the Range Object, Pivot Tables, etc. I see the following hierarchy in the Object Browser Interop.Excel Excel
1
6733
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 Duplicate() and assigning it to a new variable. But if I change the stuff in the new variable, it changes the original also. So what I need is a new copy...
2
3256
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 or Access database as following : It will connect first to the Master database (SQL or Access, connection String of this database should be read...
5
8365
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 method is normally used to convert a string to XML object. For Firefox I use E4X. For IE I use ActiveXObject loadXML() method. Thanks.
0
1441
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 face an error.
3
1509
kirubagari
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"
0
7478
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7410
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7923
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7437
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7773
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5984
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5343
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
1
1025
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
722
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.