+ Reply to Thread
Results 1 to 7 of 7

Trying to copy and paste select text based on a list box value

  1. #1
    Registered User
    Join Date
    11-05-2013
    Location
    Arlington, TX
    MS-Off Ver
    Excel 2007
    Posts
    23

    Trying to copy and paste select text based on a list box value

    I am trying to write a macro (CustSpecificESDText) to copy specific text from one worksheet (Cust Specific Text) to a different worksheet (ESD Safety Log) based on a user selection from a list box on a third worksheet (Project Info). I will modify the code to add different ranges to copy based on the selection from the list box using If Then Else. But first I want to get the syntax correct. I keep getting a syntax error on the If statement


    Sub CustSpecificESDText()
    '
    ' CustSpecificESDText Macro
    '
    '
    Dim ws As Worksheet
    If ws.("Project Info").ListBox1.Value = "Sprint" Then
    Sheets("Cust Specific Text").Select
    Range("A2:E2").Select
    Selection.Copy
    Sheets("ESD Safety Log").Select
    Range("A5:E5").Select
    ActiveSheet.Paste
    End If
    End Sub

  2. #2
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Trying to copy and paste select text based on a list box value

    You got an error because you didn't define the variable "ws". Try this (assuming Form Control listbox):

    Please Login or Register  to view this content.
    Just incase you went with activex listbox then this should work:
    Please Login or Register  to view this content.
    Last edited by stnkynts; 12-10-2013 at 03:10 PM.

  3. #3
    Registered User
    Join Date
    11-05-2013
    Location
    Arlington, TX
    MS-Off Ver
    Excel 2007
    Posts
    23

    Re: Trying to copy and paste select text based on a list box value

    Here is the workbook. Neither of the suggestions worked. Thank you for your assistance.
    Attached Files Attached Files

  4. #4
    Valued Forum Contributor Sean Thomas's Avatar
    Join Date
    03-25-2012
    Location
    HerneBay, Kent, UK
    MS-Off Ver
    Excel 2007,2016
    Posts
    971

    Re: Trying to copy and paste select text based on a list box value

    try something like this

    Please Login or Register  to view this content.
    Regards
    Sean

    Please add to my reputation if you think i helped
    (click on the star below the post)
    Mark threads as "Solved" if you have your answer
    (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code:
    [code] Your code here [code]
    Please supply a workbook containing example Data:
    It makes its easier to answer your problem & saves time!

  5. #5
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Trying to copy and paste select text based on a list box value

    Of course it didn't work. You're not using a list box.

    There are much more stable ways to do this but I already put time in so here is a quickie:
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    11-05-2013
    Location
    Arlington, TX
    MS-Off Ver
    Excel 2007
    Posts
    23

    Re: Trying to copy and paste select text based on a list box value

    Thank you for your patients and support. I just got over Cancer teatments and still have some Chemo brain so my appologies if I had a hard time following it. You have helped a great deal.

  7. #7
    Registered User
    Join Date
    11-05-2013
    Location
    Arlington, TX
    MS-Off Ver
    Excel 2007
    Posts
    23

    Re: Trying to copy and paste select text based on a list box value

    I now see why you said it wasn't a list box. When I created the reduced file I saved it as an .xlsx, realized I didn't save it as an .xlsm and saved it in that format. Unfortunately I used the .xlsx file to do that. I will play with the code now to use a listbox. Thank you again for your support.

+ 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. Select, copy, and paste text from HTML site
    By montanaheather in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-18-2013, 06:34 PM
  2. [SOLVED] Code to randomly select from a list based on Cell text value inptted
    By matrixpom in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-20-2013, 05:57 PM
  3. Sort (Copy/Paste) PDF Files based on Excel List
    By OlaAdams in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-13-2012, 04:25 PM
  4. Find Text, Select range below, copy, paste to new work sheet
    By kim5012 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-13-2011, 07:10 PM
  5. Replies: 2
    Last Post: 01-22-2011, 01:24 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