Need a macro that populates statement based on the header

m_kiran

New Member
Joined
Feb 10, 2013
Messages
3
Dear Team,

Need a macro which will create a statement based on the header information dynamically and iterate till the last row in the data in excel. Header information wont be static all the time. It changes all the time :)

empenamedept
10kiran50
20shiva30

<tbody>
</tbody>

Need to generate a excel like below based on the header information. dbname I will give manually not a problem

Insert dbname(emp,ename,dept) values(10,20,50)
Insert dbname(emp,ename,dept) values(20,shiva,30)

It should create the statements based on the number of rows it have in excel.

Appreciate your response.

Thanks,
Kiran
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
You don't necessarily need a macro:

Assuming your table starts at A1, then in cell D2 , place the following formula:

="Insert dbname("&$A$1&","&$B$1&","&$C$1&") values("&A2&","&B2&","&C2&")"

Then copy this formula down column D.

Column D will then have the statements you want.
 
Upvote 0
You don't necessarily need a macro:

Assuming your table starts at A1, then in cell D2 , place the following formula:

="Insert dbname("&$A$1&","&$B$1&","&$C$1&") values("&A2&","&B2&","&C2&")"

Then copy this formula down column D.

Column D will then have the statements you want.

Thank you very much :):). @jmacleary

I will put it more clear now.

1) I already written a macro which will retrieve the records from different tables and store the values in the excel as provided.
2)I want to insert those values into Teradata . Hence, I want the excel to generate the rows in the format below and iterate until the last row like the solution which you have provided below for inserting :).
Appreciate the response.
 
Upvote 0

Forum statistics

Threads
1,215,581
Messages
6,125,656
Members
449,246
Latest member
jbbtz28

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