Creating a macro to develop a string that uses corresponding column values

onigami

New Member
Joined
Aug 15, 2018
Messages
1
Hello. So, we're streamlining our product database on a CSV file, and one of the values is a custom field column that we have to implement as part of a larger project. The cells in this particular column have to be written out as a string similar to this:


"width=x;height=y;depth=z"


There are multiple fields we would have to use at variability, so sometimes it could be on one row


"width=x;height=y;depth=z;color=a"


While other times it's just


"width=x;depth=z;color=a"


Given the large number of products we need to edit in this manner, it would be cumbersome to do everything by hand. My thinking was to create a script that writes the string into the cells of this column, pulling values from other columns. The script would be something like...assuming the cell is A1, the value I'm looking to add is in C1, it would function that If C1 has a value, A1 would have Cfield=C1; Else skip and move to the next script function, If D1 has a value, A1 would have Dfield=D1, Else skip and move to the next script function, etc. The string in A1 would be written like


"Cfield=C1;Dfield=D1;Ffield=F1"


Assuming C1, D1 and F1 have values but E1 does not. And this script would run on every row with a value (or a selected range) I hope this makes sense.


I have a basic understanding of VBA (it's been years since I've touched VB, but I've used it in the past), but not enough to create a template of a script function that conforms to this idea. What would be the best way to go about this? Note that it can't be a non-macro formula like CONCATENATE since the database is scraping the values from the CSV and would likely scrape the formula instead of the value (Plus, many values would hence be removed from the CSV after the string is created).
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
onigami,

Welcome to the Board.

I hope this makes sense.

Posting sample data - before and after - would help clarify your description.

Cheers,

tonyyy
 
Upvote 0

Forum statistics

Threads
1,214,932
Messages
6,122,332
Members
449,077
Latest member
jmsotelo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top