+ Reply to Thread
Results 1 to 10 of 10

Modifying the column or row property of a variable?

  1. #1
    Registered User
    Join Date
    10-19-2013
    Location
    England
    MS-Off Ver
    Excel 2007/2010
    Posts
    10

    Modifying the column or row property of a variable?

    Hopefully simply done; I'm looking to change the column of a range variable directly, rather than (re-)setting the whole thing with ...=workbooks().worksheet().range("X1") or ...cells(a,b) or selection etc.

    most simply described as (non working!);
    Please Login or Register  to view this content.
    I've tried numerous confudgerations of this.

    TIA. :-)

  2. #2
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: Modifying the column or row property of a variable?

    Please Login or Register  to view this content.


    If your problem is solved, then please mark the thread as SOLVED>>Above your first post>>Thread Tools>>
    Mark your thread as Solved


    If the suggestion helps you, then Click *below to Add Reputation

  3. #3
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Modifying the column or row property of a variable?

    Hi, Googlyhead

    if you want to set it to Column H
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    If you want to offset from the existing range use the code supplied by :) Sixthsense :). But anyhow I would no rely on a Selection being made prior to running a macro.

    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  4. #4
    Registered User
    Join Date
    10-19-2013
    Location
    England
    MS-Off Ver
    Excel 2007/2010
    Posts
    10

    Re: Modifying the column or row property of a variable?

    Thanks for the input, both;
    Quote Originally Posted by HaHoBe View Post
    If you want to offset from the existing range use the code supplied by :) Sixthsense :). But anyhow I would no rely on a Selection being made prior to running a macro.
    That's part of the problem; although the variable WILL have a range, I can't rely on there being a selection - that's why I was looking for an option to modify a single parameter without using .range, .cells or a selection.
    The other two suggestions both have their own issues;
    Firstly, setting columns(8) seems to assign just a column reference to the variable, overwriting where I would preserve other parameters such as the row and sheet reference.
    And the .resize AFAIK is used to define a range from a cell. Even if I was to use .offset, it would be relative, rather than the exact column=8 I'm hoping for.

    I guess; worst case, I'll try calculating an .offset or set a new selection (without selecting!). I'd still prefer to edit a single parameter rather than redefine the whole variable.

  5. #5
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Modifying the column or row property of a variable?

    Hi, Googlyhead,

    that's why I was looking for an option to modify a single parameter without using .range, .cells or a selection.
    I beg your pardon but could you rephrase what you want to get as a result in a different way or maybe even put a sample in? What I understand by now: from not having a range-object you want to change it but without doing anything to it?

    Ciao,
    Holger

  6. #6
    Registered User
    Join Date
    10-19-2013
    Location
    England
    MS-Off Ver
    Excel 2007/2010
    Posts
    10

    Re: Modifying the column or row property of a variable?

    Hmm.ok; Example:
    Original:
    NewSerialEntry has properties of row=2, column=5, value=12345, worksheet=worksheet/sheet1 (and more...)
    after transmorgification; modifying column: (in this case, to value of 8)
    NewSerialEntry has properties of row=2, column=8, value=?, worksheet=worksheet/sheet1 (and possibly more...)

    ie. JUST the column has been changed to a specific value, retaining row and sheet references.

    I guess the value would be updated too, but that's not important.
    I'm looking at the offset possibility, but the start value could be anything from 7 to 170+

    Thanks for looking! :-)

  7. #7
    Registered User
    Join Date
    10-19-2013
    Location
    England
    MS-Off Ver
    Excel 2007/2010
    Posts
    10

    Re: Modifying the column or row property of a variable?

    What I've come up with:
    Set NewSerialEntry = NewSerialEntry.Offset(, (8 - NewSerialEntry.Column))
    Does the job!

    For some reason, I couldn't work out that subtracting the current column would give me the starting point!

    Any better way? Actually simple enough, but may as well ask...

  8. #8
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Modifying the column or row property of a variable?

    or
    Please Login or Register  to view this content.
    Entia non sunt multiplicanda sine necessitate

  9. #9
    Registered User
    Join Date
    10-19-2013
    Location
    England
    MS-Off Ver
    Excel 2007/2010
    Posts
    10

    Re: Modifying the column or row property of a variable?

    Quote Originally Posted by shg View Post
    or
    Please Login or Register  to view this content.
    I thought for a moment; "ah; that's it!", but no; using this resets the range to a new selection;
    If a different sheet is active, a completely different cell to that intended is referenced. Using the .offset preserves the worksheet.
    Likewise; modifying doesn't have the intended effect!
    Set NewSerialEntry= NewSerialEntry.Cells(NewSerialEntry.Row, "H")
    Set NewSerialEntry.Cells = NewSerialEntry.Cells(NewSerialEntry.Row, "H")

  10. #10
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Modifying the column or row property of a variable?

    I'm lost. The column property of a range (along with many other properties) is read-only.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Using a Variable in Range Property
    By Gard5096 in forum Excel Programming / VBA / Macros
    Replies: 22
    Last Post: 12-24-2012, 12:13 PM
  2. [SOLVED] Use variable property name
    By konfis in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-15-2012, 06:20 AM
  3. [SOLVED] Accessing a variable(a range) and modifying it
    By James Cornthwaite in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-30-2006, 06:10 PM
  4. [SOLVED] How to capture a Property as a variable
    By TISR in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-13-2006, 08:35 AM
  5. variable for columns(??).property
    By Neal Zimm in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-10-2005, 10:05 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1