+ Reply to Thread
Results 1 to 5 of 5

Having the user specify a column when running a macro

Hybrid View

  1. #1
    Registered User
    Join Date
    05-20-2008
    Posts
    9

    Having the user specify a column when running a macro

    Hi All,

    I have a very simple macro that I use to highlight duplicates in a column...

    Sub test()
    '
    ' test Macro
    ' Macro recorded 8/21/2008 by Corey G. Garner
    '
    
    '
        Range("A1").Select
        Selection.FormatConditions.Delete
        Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
            "=COUNTIF(A:A,A1)>1"
        Selection.FormatConditions(1).Interior.ColorIndex = 6
        Range("A1").Select
        Selection.Copy
        Columns("A:A").Select
        Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
            SkipBlanks:=False, Transpose:=False
    End Sub

    In this example, the macro is applied to column A. Is there some way that I could have a user be prompted for which column they wish to check for duplicates when they run the macro? Thanks in advance.

    -Corey
    Last edited by VBA Noob; 08-25-2008 at 01:20 PM.

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,936
    Sub test()
         Dim colSelector As String
         colSelector = InputBox("Enter a column letter")
         Worksheets("Sheet1").Columns(colSelector).Select
    End Sub
    Ben Van Johnson

  3. #3
    Registered User
    Join Date
    05-20-2008
    Posts
    9
    coooool....but how would i use it in conjunction with the macro that scans for duplicates within the selected column?

    sorry, i'm a bit of a newbie

    thanks.

    -corey

  4. #4
    Forum Contributor SOS's Avatar
    Join Date
    01-26-2004
    Location
    Glasgow, Scotland
    MS-Off Ver
    Excel 2003
    Posts
    327
    Hi corey

    Try this:

    Sub test()
    Dim cor As String
    cor = InputBox("Enter a column letter")
        Range(cor & "1").Select
            With Selection
                .FormatConditions.Delete
                .FormatConditions.Add Type:=xlExpression, Formula1:= _
                "=COUNTIF(" & cor & ":" & cor & "," & cor & "1)>1"
            End With
        Selection.FormatConditions(1).Interior.ColorIndex = 6
            Range(cor & "1").Select
                Selection.Copy
                    Columns(cor & ":" & cor).Select
                        Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
                        SkipBlanks:=False, Transpose:=False
        Application.CutCopyMode = False
        Range("A1").Select
    End Sub
    Of course you can change the name of the variable to anything you want
    Hope this helps

    Seamus

  5. #5
    Registered User
    Join Date
    05-20-2008
    Posts
    9
    worked like a CHARM

    thanks very much, Seamus

+ 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. Macro to Search, Copy/Paste onto New Sheet
    By JADownie in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-13-2008, 04:57 PM
  2. Issues pasting in column B and making 2nd macro available
    By sungsam in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 02-13-2008, 07:03 AM
  3. Error Saving after running Macro
    By millen in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-05-2007, 09:14 AM
  4. How to get last name from A Column to copy to B column
    By rd12345 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-23-2007, 06:09 PM
  5. Macro to define name range based on user input
    By truongn2 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 08-03-2007, 08:53 PM

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