简体   繁体   中英

Copy Paste Drop-Down Data using Excel VBA

I want to use VBA code in my Excel spreadsheet to copy data from one column to another. I have both checkboxes and drop-down lists. I have worked out how to copy the ticked checkboxes by copying the adjacent cell containing the TRUE and FALSE data using the following code:

Range("B1:B9").Copy Range("D1:D9")

However, the data in the drop-downs does not copy over.What do I need to add to my code to copy and paste this information?

If your dropdown is created in Range("A1") and your data validation cells are defined at B1:B9 then you need to change the data validation definition from Source =$B$1:$B$9 to =B1:B9 . If you then copy the dropdown and the data from "A1:B9" to "C1:D9" then the dropdown itself and also the data defintion is copied.

Range("A1:B9").Copy Range("D1")

After changing the Cells D1 to D9 to different values you will recognize that the new dropbox now refers to range("D1:D9").

For iCt = 1 to 9 : Range("D1").Offset(iCt,0).Value = iCt + 10 : next iCt

;-)

I added in the following to copy and paste the dropdowns:

Range("B10:B15").Select
    Selection.Copy
    Range("D10:D15").Select
    ActiveSheet.Paste

Thank you to those who answered my question and helped me to get to an answer that worked.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM