+ Reply to Thread
Results 1 to 4 of 4

A simple Excel Macro

  1. #1
    Registered User
    Join Date
    05-25-2010
    Location
    East Midlands
    MS-Off Ver
    Excel 2007
    Posts
    5

    A simple Excel Macro

    Hello,

    I am just trying to write my first Macro in Excel (2007). I want to have a field in an excel sheet that asks users to input a number, say "5".

    I then want to number the columns on another sheet according to this number, i.e.
    1|2|3|4|5

    If the user entered "3" in the field, then the columns should be numbered 1|2|3.

    It would be great if someone could help me with that.
    Thanks,
    Lily.

  2. #2
    Forum Expert
    Join Date
    12-23-2006
    Location
    germany
    MS-Off Ver
    XL2003 / 2007 / 2010
    Posts
    6,326

    Re: A simple Excel Macro

    Your post does not comply with Rule 1 of our Forum RULES. Your post title should accurately and concisely describe your problem, not your anticipated solution. Use terms appropriate to a Google search. Poor thread titles, like Please Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will be addressed according to the OP's experience in the forum: If you have less than 10 posts, expect (and respond to) a request to change your thread title. If you have 10 or more posts, expect your post to be locked, so you can start a new thread with an appropriate title.
    To change a Title on your post, click EDIT then Go Advanced and change your title, if 2 days have passed ask a moderator to do it for you.

  3. #3
    Registered User
    Join Date
    05-25-2010
    Location
    Trinidad
    MS-Off Ver
    Excel 2007
    Posts
    29

    Re: A simple Excel Macro

    try this-This assumes that the number of columns you want is in Sheet1 cells(1,1), adjust accordingly. Also if you wanted a popup box to request the user enter it there, that can be done as well with a few mods.

    Option Explicit
    Public Sub LabelCols()
    Dim i, NoOfCols As Long
    i = 1
    NoOfCols = Sheets("Sheet1").Cells(1, 1)
    While (i <= NoOfCols)
    Sheets("Sheet2").Cells(1, i) = i 'Your request was for only the column headers
    i = i + 1
    Wend
    End Sub

  4. #4
    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: A simple Excel Macro

    Avinash,

    Please take a few minutes to read all of the forum rules before posting again.

    Thanks.
    Entia non sunt multiplicanda sine necessitate

+ 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