VBA Code: Search and Copy Data Between Worksheets
This VBA code searches for values in the "FROM NIPI EMA(20230530)" worksheet and copies corresponding values from the "FROM VELE EMA(20230530)" worksheet. \n\nHere's a breakdown of the code:\n\n1. Declare and initialize variables:\n- nipiSheet: Represents the "FROM NIPI EMA(20230530)" worksheet.\n- veleSheet: Represents the "FROM VELE EMA(20230530)" worksheet.\n- nipiRange: Represents the range of values in column D of the nipiSheet.\n- veleRange: Represents the range of values in column G of the veleSheet.\n- nipiLastRow: Stores the last row number in column D of nipiSheet.\n- veleLastRow: Stores the last row number in column G of veleSheet.\n- nipiCell: Represents each cell in the nipiRange.\n- veleCell: Represents each cell in the veleRange.\n- searchValue: Stores the value to search for in veleSheet.\n- foundCells: Stores the range of cells where the searchValue is found in veleSheet.\n- copyValue: Stores the copied values from veleSheet.\n\n2. Set the nipiSheet and veleSheet variables to the respective worksheets.\n\n3. Determine the last row number in column D of nipiSheet and set the nipiRange accordingly.\n\n4. Disable screen updating, calculation, and events to improve performance.\n\n5. Loop through each cell in nipiRange.\n\n6. Get the searchValue from the current nipiCell.\n\n7. Find all matching cells in veleSheet based on the searchValue.\n\n8. If matching cells are found (foundCells is not Nothing), copy the corresponding values from column E of veleSheet and concatenate them with commas.\n\n9. Remove the last comma from the copyValue.\n\n10. Add the copyValue to the cell in column F of nipiSheet (one column offset from nipiCell).\n\n11. Repeat steps 5-10 for each nipiCell.\n\n12. Enable screen updating, calculation, and events.\n\n13. Display a message box indicating that the search and copy process is complete.\n\nNote: Make sure to replace "FROM NIPI EMA(20230530)" and "FROM VELE EMA(20230530)" with the actual names of your worksheets.
原文地址: https://www.cveoy.top/t/topic/p3hr 著作权归作者所有。请勿转载和采集!