+ Reply to Thread
Results 1 to 8 of 8

how should I solve this with FOR loop

  1. #1
    Registered User
    Join Date
    12-13-2011
    Location
    Finland
    MS-Off Ver
    Excel 2007
    Posts
    7

    Question how should I solve this with FOR loop

    Hello,
    i have the following problem:

    write a program in Visual Basic which inputs an integer n, and produces the following pattern in Excel.In this example, n equals 15, and it has to be an odd number.
    \1


    can anyone help me? Tnx
    Last edited by Hard; 12-14-2011 at 04:22 AM.

  2. #2
    Valued Forum Contributor
    Join Date
    12-05-2011
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010 & 2013
    Posts
    308

    Re: how should i solve this...

    Hi

    You will need to change your thread title before we can help you. It should contain a description of the problem. Sorry, I know it sounds a bit petty, but these are the forum rules and it will allow others to search and benefit from this thread. Please Go to Edit Post, Go Advanced.

    The good news is that I think this is fairly easy and we can quickly solve it once the thread title is fixed.

    Cheers, Rob.
    Last edited by rscsmith; 12-13-2011 at 06:28 PM.

  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: how should I solve this with FOR loop

    Hi,

    Sounds like an exam question so rather than give you the answer I'll suggest a method.

    1. Set up two variables, one a loop counter (say x) and the other an inputbox 'n' variable - in your example 15.
    2. Create a For Next loop using the loop counter variable which loops from 1 to n
    3. Within the loop add four lines of code. The first two lines to colour the row x & column x cell black and the row x and n-x+1 cells black, the second two lines to colour the row x + n, column x cell black and the row x + n and column n-x+1 cell black.

    Regards
    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.

  4. #4
    Registered User
    Join Date
    12-13-2011
    Location
    Finland
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: how should i solve this...

    Done. Sorry about that!

  5. #5
    Registered User
    Join Date
    12-13-2011
    Location
    Finland
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: how should I solve this with FOR loop

    Quote Originally Posted by Richard Buttrey View Post
    Hi,

    Sounds like an exam question so rather than give you the answer I'll suggest a method.

    1. Set up two variables, one a loop counter (say x) and the other an inputbox 'n' variable - in your example 15.
    2. Create a For Next loop using the loop counter variable which loops from 1 to n
    3. Within the loop add four lines of code. The first two lines to colour the row x & column x cell black and the row x and n-x+1 cells black, the second two lines to colour the row x + n, column x cell black and the row x + n and column n-x+1 cell black.

    Regards
    it's not an exam question.
    Last edited by Hard; 12-15-2011 at 06:37 AM.

  6. #6
    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: how should I solve this with FOR loop

    Hi,

    This was the method I had in mind

    Please Login or Register  to view this content.
    Regards

  7. #7
    Valued Forum Contributor
    Join Date
    12-05-2011
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010 & 2013
    Posts
    308

    Re: how should I solve this with FOR loop

    Hi

    Thanks for updating the title - was itching to respond!

    Here's my version of the code:
    Please Login or Register  to view this content.
    Cheers, Rob.

  8. #8
    Registered User
    Join Date
    12-13-2011
    Location
    Finland
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: how should I solve this with FOR loop

    Hi,
    Thanks all of you for helping me!

    Regards

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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