Copy same info to the another sheet VBA

Halos

New Member
Joined
Feb 14, 2015
Messages
34
Hi,

Please see below code. When I run macro, info copying to sheet1. But I need at the same time to copy same information to sheet2. Please help.

Code:
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("Sheet1")

ws.Cells(iRow, 2).Value = Me.combobox_name.Value
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Just add another sheet reference and line of code that assigns the value, i.e.
Code:
Dim iRow As Long
Dim ws As Worksheet
[COLOR=#ff0000]Dim ws2 As Worksheet[/COLOR]

Set ws = Worksheets("Sheet1")
[COLOR=#ff0000]Set ws2 = Worksheets("Sheet2")[/COLOR]

ws.Cells(iRow, 2).Value = Me.combobox_name.Value
[COLOR=#ff0000]ws2.Cells(iRow, 2).Value = Me.combobox_name.Value[/COLOR]
I trust the value if iRow is being set somewhere prior to this code.
 
Upvote 0
Just add another sheet reference and line of code that assigns the value, i.e.
Code:
Dim iRow As Long
Dim ws As Worksheet
[COLOR=#ff0000]Dim ws2 As Worksheet[/COLOR]

Set ws = Worksheets("Sheet1")
[COLOR=#ff0000]Set ws2 = Worksheets("Sheet2")[/COLOR]

ws.Cells(iRow, 2).Value = Me.combobox_name.Value
[COLOR=#ff0000]ws2.Cells(iRow, 2).Value = Me.combobox_name.Value[/COLOR]
I trust the value if iRow is being set somewhere prior to this code.


Thanks Joe, but when copying information to sheets, which command we need to add in order to
highlight also border (for example: Borders(xlInsideHorizontal).LineStyle = xlNone)
 
Upvote 0
Thanks Joe, but when copying information to sheets, which command we need to add in order tohighlight also border (for example: Borders(xlInsideHorizontal).LineStyle = xlNone)
That seems to be an entirely different question than the original one you posted.

If you want to copy formatting too, you will need to use Copy commands. You can use the Format Painter to copy formats.
If you turn on the Macro Recorder, and record yourself doing it manually, it should give you the code you need.
 
Upvote 0
That seems to be an entirely different question than the original one you posted.

If you want to copy formatting too, you will need to use Copy commands. You can use the Format Painter to copy formats.
If you turn on the Macro Recorder, and record yourself doing it manually, it should give you the code you need.


Many Thanks Joe.
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,155
Members
453,021
Latest member
Justyna P

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