copy and paste rows from a table with fewer columns

patodif

New Member
Joined
Apr 7, 2023
Messages
4
Office Version
  1. 365
Platform
  1. Windows
Hello, I have a table in an excel sheet, from which I must select a range of rows with the mouse and these are passed to another table in another sheet. The source table has 5 columns and the destination one only 3 (which I select) but when I pass them it does not keep the table format or adds it below the table lines. Somebody could help me?
Thanks a lot

Sub SeleccionConteo()

Dim uF As Long

Dim Centro As String

Dim Tablacentro As String

Dim Tabladestino As ListObject





Tablacentro = "TablaC" & Range("E3")





Centro = Sheets("Stock").Range("E3")

uF = Worksheets(Centro).Cells(Rows.Count, 10).End(xlUp).Row

Set Tabladestino = Sheets(Centro).ListObjects(Tablacentro)



Selection.Select

Application.CutCopyMode = False

Selection.Copy

Sheets(Centro).Select Destination:=Sheets(Centro).Range("A" & uF + 1)
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Are both tables just rows and columns in a worksheet or are you using Excel tables? Which columns from the first table are copied into the second table? How do you specify which columns to copy?
 
Upvote 0
Hello, and thanks, they are excel tables. I can indicate the columns that are copied but not the rows, nor the beginning of the rows to count, for this reason I use "Selection".
The source table has 6 columns and the destination table has 10 columns, the first 6 match in order and name.
I wil try with this:
Sub SeleccionConteo()



Dim uF As Long

Dim Centro As String

Dim Tablacentro As String

Dim Tabladestino As ListObject

Dim NuevaFila As ListRow



Tablacentro = "TablaC" & Range("E3")



Centro = Sheets("Stock").Range("E3")

uF = Worksheets(Centro).Cells(Rows.Count, 10).End(xlUp).Row

Set Tabladestino = Sheets(Centro).ListObject(Tablacentro)





Selection.Select

Application.CutCopyMode = False

Selection.Copy

Sheets(Centro).Select

Sheets(Centro).ListObject(Tabladestino).ListRow.Paste
 

Attachments

  • Captura de pantalla 2023-04-08 184623.png
    Captura de pantalla 2023-04-08 184623.png
    86.7 KB · Views: 2
Upvote 0
Ideally you share your workbook with the forum so someone that is helping does not need to recreate it. Use a link to Box, Dropbox or 1Drive.

From the five columns in the source table do you always copy the same three columns to the target table? If not the data in the target table will not be consistent?
 
Upvote 0
Ideally you share your workbook with the forum so someone that is helping does not need to recreate it. Use a link to Box, Dropbox or 1Drive.

From the five columns in the source table do you always copy the same three columns to the target table? If not the data in the target table will not be consistent?
TEST1.xlsm
ABCDEFGHIJK
8AlmacénUbi. por defectoUbicaciónFamiliaSubfamiliaArtículoDescripciónProveedor Hab.Ref. proveedorPie. Stk. ActualPrecio Pie.
928000505190263181COBRE MTS TUBO TIRAS 10X12 MM (5M)73710D12X100702,92838823
1028000504190263182COBRE MTS TUBO TIRAS 13X15 MM (5M)73710D15X1001053,50295126
1128000503190263184COBRE MTS TUBO TIRAS 16X18 MM (5M)73710D18X1001104,25220211
1228000502190263185COBRE MTS TUBO TIRAS 20X22 MM (5M)73710D22X100955,16745806
1328000501190263186COBRE MTS TUBO TIRAS 26X28 MM (5M)73710D28X100906,79645623
1428000701190263187COBRE MTS TUBO TIRAS 33X35 MM (5M)737SD350100608,98890392
1528000702190263188COBRE MTS TUBO TIRAS 40X42 MM (5M)73710D42X1005011,10526686
1628000703190263189COBRE MTS TUBO TIRAS 54X1,2 MM (5MT)73710D54X1204018,70977910
1728000704190263190COBRE MTS TUBO TIRAS 64 X 1.5 MM (5 MTS)73761642025,86847059
1824111902190253191COBRE MTS TUBO ROLLO 8X10 MM (50M)73710R10X100992,16779063
1924110903190253192COBRE MTS TUBO ROLLO 10X12 MM (50M)73710R12X1001162,92141946
2028000803190253193COBRE MTS TUBO ROLLO 12X15 1,5MM (50 M)7373193535,69488420
2124110902190253194COBRE MTS TUBO ROLLO 13X15 MM (50M)73710R15X1001683,62666801
2228000802190253196COBRE MTS TUBO ROLLO 15X18 1,5MM (25 M)7373196346,99606283
2324110901190253197COBRE MTS TUBO ROLLO 16X18 MM (50M)73710R18X1002044,29489560
2428000801190253198COBRE MTS TUBO ROLLO 19X22 1,5MM (25 M)73710RG22X150628,91229405
2524110904190273199COBRE MTS TUBO ROLLO CROM 8X10 MM (25M)73710CR10X100112,85642118
2624111104190273200COBRE MTS TUBO ROLLO CROM 10X12 MM (25M)73710CR12X100342,94759806
2721603105190293201COBRE ROLLO FRIGORIFICO 1/4"X0,8 (15M)737FRI1/4418,98888102
2821603305190293202COBRE ROLLO FRIGORIFICO 3/8"X0,8 (15M)737FR3/8429,61263530
2921603505190293203COBRE ROLLO FRIGORIFICO 1/2"X0,8 (15M)737FR1/2438,44132727
3021603705190293204COBRE ROLLO FRIGORIFICO 5/8"X0,8 (15M)737FR5/8232,39776114
Stock
Cells with Conditional Formatting
CellConditionCell FormatStop If True
G8:G87019Cell ValueduplicatestextNO
 
Upvote 0
I have 11 of this one, but with different names, so the name is a variant.
TEST1.xlsm
ABCDEFGHIJKLMNOPQ
10AlmacénUbi. por defectoUbicaciónFamiliaSubfamiliaArtículoDescripciónProveedor Hab.Ref. proveedorPie. Stk. ActualPrecio Coste Pie.contadodiferncia imp diffechaIncidenciaMotivo
1128000503190263184COBRE MTS TUBO TIRAS 16X18 MM (5M)73710D18X1001104,25220211-110-467,74
1228000505190263181COBRE MTS TUBO TIRAS 10X12 MM (5M)73710D12X100702,92838823-70-204,99
1328000504190263182COBRE MTS TUBO TIRAS 13X15 MM (5M)73710D15X1001053,50295126-105-367,81
1428000503190263184COBRE MTS TUBO TIRAS 16X18 MM (5M)73710D18X1001104,25220211-110-467,74
1528000502190263185COBRE MTS TUBO TIRAS 20X22 MM (5M)73710D22X100955,16745806-95-490,91
1628000501190263186COBRE MTS TUBO TIRAS 26X28 MM (5M)73710D28X100906,79645623-90-611,68
1728000701190263187COBRE MTS TUBO TIRAS 33X35 MM (5M)737SD350100608,98890392-60-539,33
1828000705190533229PP-R MTS TUBO 20 MM (4M)67408406200,00
1928000905190533230PP-R MTS TUBO 25 MM (4M)67408406300,00
2028000904190533231PP-R MTS TUBO 32 MM (4M)67408406400,00
2
Cell Formulas
RangeFormula
M11:M20M11=+L11-J11
N11:N20N11=+M11*K11
Cells with Conditional Formatting
CellConditionCell FormatStop If True
G18:G20Cell ValueduplicatestextNO
G12:G17Cell ValueduplicatestextNO
G11Cell ValueduplicatestextNO
J18:J2520Expression=M18<0textNO
J18:J2520Expression=M18>0textNO
K18:L2520,L11:L17Expression=M11>0textNO
K18:L2520,L11:L17Expression=M11<0textNO
M7:N9,M6,M1:N3,M5:N5,L4:M4,M11:N1048576Cell Value<0textNO
M7:N9,M6,M1:N3,M5:N5,L4:M4,M11:N1048576Cell Value>0textNO
N18:N990Cell Value<0textNO
N18:N990Cell Value>0textNO
N18:N990Expression=#¡REF!>0textNO
N18:N990Expression=#¡REF!<0textNO
 
Upvote 0

Forum statistics

Threads
1,215,202
Messages
6,123,625
Members
449,109
Latest member
Sebas8956

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