+ Reply to Thread
Results 1 to 3 of 3

How to Loop through Column and Modify Values Based on User Input

  1. #1
    Registered User
    Join Date
    04-14-2014
    Location
    Atlanta, GA, USA
    MS-Off Ver
    Excel 2016
    Posts
    46

    How to Loop through Column and Modify Values Based on User Input

    Hi,

    I have a file where I need a macro to search for a value of 0 in the first column and then do one of the following:

    (1) Change the value in the active cell in column A where the 0 was found to a value of 9, copy the value from one row up in column B (Offset(-1,1), and paste that value into column B in the same row where the 0 was found (Offset(0,1).
    (2) Change the value in the active cell in column A where the 0 was found to a value of 9, copy the value from one row below in column B (Offset(1,1), and paste that value into column B in the same row where the 0 was found (Offset(0,1).
    OR
    (3) Choose to leave the value in the active cell in column A as 0.

    The macro opens a TXT file, moves some columns, and then searches for the value 0 in column A. The basics of that are below. I would like to add some buttons to the TXT file which would allow the user to click on one button to perform the action in #1 above, to click on a second button to perform the action in #2 above, or to click on a third button to leave the value as is, with any of these buttons clicked then looping to the next found instance of 0 after performing the action. Unfortunately, my looping programming skills are weak and I'm not sure at all how to proceed with creating buttons on the fly to do this. Any help you can provide would be greatly appreciated!

    Thanks!

    Bryan
    Please Login or Register  to view this content.
    Last edited by Leith Ross; 10-23-2015 at 06:07 PM. Reason: Added Code Tags

  2. #2
    Forum Expert
    Join Date
    10-09-2014
    Location
    Newcastle, England
    MS-Off Ver
    2003 & 2013
    Posts
    1,986

    Re: How to Loop through Column and Modify Values Based on User Input

    Im sure theres loads of different ways, heres my thoughts.

    1. To cycle through column A looking for zeros:

    Public currRow As Integer

    Please Login or Register  to view this content.
    The Id have a userform (in this example called frmAction) with 3 buttons and the following code

    Please Login or Register  to view this content.
    You'd obviousy change the msgbox line to whatever actions you need

    I tried to upload a basic example but the forums playing up
    If someone has helped you then please add to their Reputation

  3. #3
    Registered User
    Join Date
    04-14-2014
    Location
    Atlanta, GA, USA
    MS-Off Ver
    Excel 2016
    Posts
    46

    Re: How to Loop through Column and Modify Values Based on User Input

    Hi,

    That was a helpful start. I added DIM statements for the wsCell and currRow to make it mostly work. Some code was needed to identify if there are no cells with the value of 0. If that is the case, the code stops and produces a message like the one shown below. Finally, if a 0 is found, code was added to scroll to the cell with the 0 value so that row can be seen so that the user knows which option to select (i.e., which CommandButton to click) on the UserForm.

    However, there are a few things that still need to be solved. The values of the cells are for some reason not getting updated. Also, since one of the user's options on the UserForm is to not modify the value of 0, the code needs to exit once all of the records have been reviewed.

    I have attached my modified code to give you an idea of where I'm trying to go, but it's not producing the desired results. Any more direction you can provide will be greatly appreciated!

    Please Login or Register  to view this content.
    Last edited by bryanmarks; 10-26-2015 at 12:48 PM.

+ 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] Formula to compare different values in different columns based on user input
    By duffer in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 09-15-2015, 05:25 AM
  2. Replies: 7
    Last Post: 01-26-2015, 04:24 PM
  3. Incremental values based on user input
    By hanumanthindirala in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-18-2013, 02:34 PM
  4. Returning Values based on multiple user input
    By ahelman in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-20-2012, 01:24 PM
  5. Using text box input to lookup number and replace based on user input into new column
    By harl3y412 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-28-2011, 03:15 PM
  6. let user select input file, modify, save
    By alanders in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-25-2010, 06:37 PM
  7. Do while Loop that is conditional based upon user input?
    By gplush in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-21-2009, 02:01 AM

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