Select Text and Inserting into Pre-determined Text

barrettdavis01

New Member
Joined
Oct 2, 2012
Messages
3
Hello,

I am new to macro's, but I learn very quickly.


[TABLE="width: 500"]
<tbody>[TR]
[TD]slot[/TD]
[TD]port[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]21[/TD]
[/TR]
[TR]
[TD]6[/TD]
[TD]23[/TD]
[/TR]
[TR]
[TD]6[/TD]
[TD]11[/TD]
[/TR]
</tbody>[/TABLE]

I would like to select these 3 rows(or any number of rows) and insert them into text that looks like this:

This will need a loop based upon selected rows? I don't know if this is possible.

Conf T
int g 1/21
no desc
sw ac vlan 1
speed auto
end

Conf T
int g 6/23
no desc
sw ac vlan 1
speed auto
end

Conf T
int g 6/11
no desc
sw ac vlan 1
speed auto
end



Thank you for your help,

This an insightful forum.


-- Barrett
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
You haven't indicated where the data is, so you'll need to modify this suggestion:
Code:
Dim i as Long
For i = 1 to 3
  msgbox Range("A" & i) & "/" & Range("B" & i)
Next i
 
Upvote 0
If your output is to go into a cell on the same row as its slot/port numbers is on, and assuming slot is in Column A and port is in Column B, put this formula in an empty cell on the same row as the first piece of data and copy down as needed...

="Conf T"&CHAR(10)&"int g "&A2&"/"&B2&CHAR(10)&"no desc"&CHAR(10)&"sw ac vlan 1"&CHAR(10)&"speed auto"&CHAR(10)&"end"

Don't forget to change the alignment for the cells the formulas are in to "wrap text".
 
Upvote 0
If your output is to go into a cell on the same row as its slot/port numbers is on, and assuming slot is in Column A and port is in Column B, put this formula in an empty cell on the same row as the first piece of data and copy down as needed...

="Conf T"&CHAR(10)&"int g "&A2&"/"&B2&CHAR(10)&"no desc"&CHAR(10)&"sw ac vlan 1"&CHAR(10)&"speed auto"&CHAR(10)&"end"

Don't forget to change the alignment for the cells the formulas are in to "wrap text".

Thank you for your answers. They were both very helpful. One more quick note, when this equation is used it outputs text in quotes(exp: "int g askjdksadjsa blah blah").

I need to be able to have this text without quotes. How do I remove these?




---Barrett
 
Upvote 0
One more quick note, when this equation is used it outputs text in quotes(exp: "int g askjdksadjsa blah blah").

I need to be able to have this text without quotes. How do I remove these?
There is nothing in the formula that I posted will generate quote marks in the text that it displays. Did you copy/paste the formula I posted exactly as I posted it? Or did you modify it in some way? If yes, show us how.
 
Upvote 0
There is nothing in the formula that I posted will generate quote marks in the text that it displays. Did you copy/paste the formula I posted exactly as I posted it? Or did you modify it in some way? If yes, show us how.

If you copy the cells that are ouputted from this equation and then paste them into word/notepad..

[TABLE="width: 269"]
<TBODY>[TR]
[TD]"Conf T
int g 1/21
no desc
sw ac vlan 1
speed auto
end"

-- CLI can't read these quotes unfortunately.[/TD]
[/TR]
</TBODY><COLGROUP><COL></COLGROUP>[/TABLE]
 
Upvote 0
If you copy the cells that are ouputted from this equation and then paste them into word/notepad..

[TABLE="width: 269"]
<tbody>[TR]
[TD]"Conf T
int g 1/21
no desc
sw ac vlan 1
speed auto
end"

-- CLI can't read these quotes unfortunately.
[/TD]
[/TR]
</tbody>[/TABLE]
It looks like those quote marks appear no matter where you paste the copy to. It appears that the quotes come about in that process because of the Line Feed characters. If you put this formula in a cell...

="FirstName"&"SecondName"

if copy/pastes without quote marks, but if you change it to this...

="FirstName"&CHAR(10)&"SecondName"

then you get the quote marks when you copy/pasted it. I do not know how, or even if it is possible, to turn this "feature" off.
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,289
Members
452,631
Latest member
a_potato

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