简体   繁体   中英

Concatenating text cells and copy/pasting between workbooks with VBA in Excel

I have two Excel files: one with a lot of raw data from a CRM database, and one with sanitized/organized data. I need to copy addresses from the raw data workbook to the organized workbook.

The problem is that the raw data file stores the addresses as two columns: one column for the street/city/state, and one for the country. The organized workbook needs street/city/state/country, all in one column. So I need to concatenate the two columns in the raw data workbook, and paste them into the organized workbook. Like so:

Workbook 1 (Raw Data):
Street/City/State                 Country
1060 W. Addison, Chicago, IL      United States

   |
   v

Workbook 2 (Organized):
Street, City, State, Country
1060 W. Addison, Chicago, IL, United States

I know how to copy/paste between workbooks, and I know how to concatenate two text cells, but I can't seem to make the two work together.

I think the following suggestion will help you. Use basic knowledge like this suppose in your first workbook street/city/state is in A column and country is in B column. Using VBA you can get a cell value easily by using cell.

Range("A1").Value & " , " & Range("B1").Value 

The above will give the result 1060 W. Addison, Chicago, IL, United States

Now copy this value into the cell in another workbook where you want. You already said you know how to copy values from one workbook to another workbook.

If this helps you vote for my answer

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