+ Reply to Thread
Results 1 to 5 of 5

How to apply 'for' loop for repetitive tasks in multiple column

  1. #1
    Registered User
    Join Date
    01-04-2021
    Location
    India
    MS-Off Ver
    2016
    Posts
    2

    How to apply 'for' loop for repetitive tasks in multiple column

    Hi All,

    I am new to VBA coding and would be great if anyone can help me with the below two points:

    1. I have written a code however not able to put it into a for loop, so that i can stop rewriting the same code for multiple columns, secondly i am not able to add piece of code to replace single backslash with double backslash in the same code, below is the code i am using:

    Please Login or Register  to view this content.
    2. Another question i have is, if in a particular cell i have 2 values with '.' (dot) separator i can replace it with ',' (comma) or if there are multiple spaces i can trim it to one space however, if there is 1 value in the same cell its still replacing it with ',' as per the above rule, as for single value i just want to trim with single space or remove the dot if any.

    EX:

    'ABC. DEF' should get replaced as 'ABC,DEF' by removing space and replace the dot'.' with comma',' (below code is working till here)
    if it's only 'ABC .' its converting it as 'ABC,'
    What amendment i can make here so it becomes only 'ABC' (trim the space and remove any special character) in case of single value in that cell.

    Using the below code:

    Please Login or Register  to view this content.
    Thanks!
    Last edited by Ronith; 01-06-2021 at 04:47 AM.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,447

    Re: How to apply 'for' loop for repetitive tasks in multiple column

    Rather than using column letters, use column numbers in your cell references. Then you can have an outer loop where you vary the column number.

    Administrative Note:

    Welcome to the forum.

    You need to include code tags around your code.

    Please take a moment to add the tags. Posting code between tags makes your code much easier to read and copy for testing, and it also maintains VBA formatting.

    Please see Forum Rule #2 about code tags and adjust accordingly. Click on Edit to open your post, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    (Note: this change is not optional.)
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    01-04-2021
    Location
    India
    MS-Off Ver
    2016
    Posts
    2

    Re: How to apply 'for' loop for repetitive tasks in multiple column

    Thanks for your note TMS..i have used the relevant tags now. please let me know if it isn't fine.

    Is it feasible for you to amend my code on how can i use the outer loop, also regarding second point do you have any idea how can i amend this.

    Many Thanks!

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,447

    Re: How to apply 'for' loop for repetitive tasks in multiple column

    This is the code to use an Outer Loop for the columns

    Please Login or Register  to view this content.
    As for the second question, use InStr to check for the character.

    For example:

    Please Login or Register  to view this content.

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,447

    Re: How to apply 'for' loop for repetitive tasks in multiple column

    Thanks for the rep.


    I trust it has helped you.

+ 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] Repetitive tasks on forms
    By NickNunes in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 11-19-2018, 04:22 AM
  2. Daily Excel Reports, repetitive daily tasks
    By Lisa_NYC in forum Excel General
    Replies: 13
    Last Post: 10-15-2014, 02:46 PM
  3. Creating loop to apply to multiple textboxes
    By acwhite42 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-04-2013, 11:53 AM
  4. Loop for repetitive code
    By jackandjill in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 10-18-2010, 10:18 PM
  5. automating repetitive tasks
    By hoshino in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-09-2009, 01:43 AM
  6. [SOLVED] Macro -- repetitive tasks
    By OTS in forum Excel General
    Replies: 1
    Last Post: 10-07-2005, 12:05 PM
  7. [SOLVED] Using macro to run repetitive tasks
    By OTS in forum Excel General
    Replies: 1
    Last Post: 10-07-2005, 09:05 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