+ Reply to Thread
Results 1 to 10 of 10

Creating a range based on values in selected column.

  1. #1
    Registered User
    Join Date
    11-29-2018
    Location
    England
    MS-Off Ver
    2016
    Posts
    6

    Creating a range based on values in selected column.

    Hi everyone,

    I am trying to write a code which will look at a specific column, and save a range of cells of that column which contain "QF". I will then use the retrieved range to insert formulas into next columns but only in rows where the string was detected.

    Here is the code I have so far:

    Please Login or Register  to view this content.
    This code doesnt give any error, it is just not doing anything. Is anyone able to advise on how this needs to be changed?

    Kind Regards
    Emil
    Last edited by Richard Buttrey; 11-30-2018 at 09:50 AM.

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Creating a range based on values in selected column.

    Code Tags Added
    Your post does not comply with Rule 2 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found at http://www.excelforum.com/forum-rule...rum-rules.html



    (I have added them for you today. Please take a few minutes to read all Forum Rules and comply in the future.)
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Creating a range based on values in selected column.

    Please clarify what you are trying to do. Better still upload the workbook and manually add the results you expect.

    Just as an aside I can see you have dimmed some variables but not Range0. I guess you don't have Option Explicit at the top of the module otherwise VBA would have bombed out.

    Is there really a need for VBA? At first glance a simple Excel IF function could probably achieve what you want.

  4. #4
    Registered User
    Join Date
    11-29-2018
    Location
    England
    MS-Off Ver
    2016
    Posts
    6

    Re: Creating a range based on values in selected column.

    Thanks for the reply.

    This code is a part of a bigger script which will go through 100s of excel spreadsheets to fix existing formulas so I want it to work like this:

    1. Go into spreadsheet
    2. Check the Column B to find how many rows are relevant. Rows are numbered QF1 QF2 QF3 QF4 etc. All spreadsheets have different amount of rows, I only want to focus on rows that have something in them.
    3. Save the range of rows in which QF was found
    4. Insert formulas into other columns but only in those relevant rows.

    So the bit below should look at Column B and save the starting cell and ending cell:

    Please Login or Register  to view this content.
    Then I want to use those starting and ending cells to insert a formula into these relevant rows, but in neighboring column. I replaced the actual formula with =2+2 to simplify it, the formula i need works fine when i
    specify the range like this:
    Please Login or Register  to view this content.
    But as I want to insert the formulas only into to the relevant rows in which "QF" was found, I am trying to do that by using the saved start and end cells from the loop above:
    Please Login or Register  to view this content.
    For some reason I am not able to attach the spreadsheet file?
    Last edited by efijal; 11-30-2018 at 10:42 AM.

  5. #5
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Creating a range based on values in selected column.

    Hi,

    To upload a file use the Go Advanced button. Underneath the post area you'll see a Manage Attachments option. And don't forget to manually add some typical results.

  6. #6
    Valued Forum Contributor
    Join Date
    11-28-2015
    Location
    indo
    MS-Off Ver
    2016 64 bitt
    Posts
    1,285

    Re: Creating a range based on values in selected column.

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    11-29-2018
    Location
    England
    MS-Off Ver
    2016
    Posts
    6

    Re: Creating a range based on values in selected column.

    I've attached the excel file, the VBA script is in there. I've added some text boxes for explanation.

    The aim is to automatically detect the range of rows in which QF values are, and then be able to use that range to input formulas into any other chosen columns using:

    Please Login or Register  to view this content.
    I was able to insert those formulas by using a FOR loop, but I have hundreds of rows and about 10 columns to have formulas inserted into, so it was taking ages for the script to go into every cell and input them one by one. By being able to automatically detect this range, the script will be able to use the command above which makes it much faster.
    Attached Files Attached Files

  8. #8
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,613

    Re: Creating a range based on values in selected column.

    Please Login or Register  to view this content.
    Last edited by protonLeah; 12-06-2018 at 04:29 PM.
    Ben Van Johnson

  9. #9
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,316

    Re: Creating a range based on values in selected column.

    Administrative Note:
    HTH
    Regards, Jeff

  10. #10
    Registered User
    Join Date
    11-29-2018
    Location
    England
    MS-Off Ver
    2016
    Posts
    6

    Re: Creating a range based on values in selected column.

    Quote Originally Posted by protonLeah View Post
    Please Login or Register  to view this content.
    Thank you so much it worked!

+ 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] Creating a range projection based on two values
    By colemc18 in forum Excel Formulas & Functions
    Replies: 11
    Last Post: 09-07-2018, 07:33 PM
  2. Replies: 3
    Last Post: 07-24-2018, 12:07 PM
  3. [SOLVED] VBA Creating a list of unique values from one column based on criteria from another column
    By bilbo85 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-09-2016, 02:38 PM
  4. Replies: 4
    Last Post: 04-26-2015, 12:18 PM
  5. [SOLVED] Sum selected values in matrix based on date range as well as unique identifier in row
    By smansyd in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 07-09-2014, 07:56 PM
  6. Creating a report based off existing values 'selected' in a form - Where to start
    By PeterJFulton in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 04-02-2014, 06:24 AM
  7. Replies: 0
    Last Post: 08-10-2012, 12:55 PM

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