help with excel macro.

Posted on 2011-05-04
Last Modified: 2012-05-11
Hi there,

I need to write a macro on excel when user press the button, I need to put  "-X" to the end of the data on Column F.

I have no idea on how to do it for the user in quickest manner. I really need your help guys.

Question by:koala-london

    Author Comment

    I mean I need to append the data "-X" to the end of the cell on column F.

    might have to create loop where we don't know how long the column will be.
    LVL 23

    Accepted Solution

    Try this code:

    Sub AddX()
        Dim Num As Integer
        Dim Cell As String
        Num = 1
        Cell = "F" & 1
        Do Until Range(Cell).Value = ""
            If Range(Cell).Value <> "" Then
                Range(Cell).Value = Range(Cell).Value & "-X"
                Num = Num + 1
                Cell = "F" & Num
            End If
    End Sub

    Open in new window


    Author Comment

    This perfectly works as i want. But i want to trigger it from button. i will close it and open it new question for you as it is another topics.


    Please help me how to trigger it from button.

    Author Closing Comment

    the answer is spot on. thanks

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Sparklines have been introduced with Excel 2010 and are a useful tool for creating small in-cell charts, used for example in dashboards. Excel 2010 offers three different types of Sparklines: Line, Column and Win/Loss. What it does not offer is a…
    This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
    The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
    This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now