Add parts of row to table

Luke777

Board Regular
Joined
Aug 10, 2020
Messages
246
Office Version
  1. 365
Platform
  1. Windows
Hi all,

Rows 1 to X (generally somewhere around 30 but could be less) contain data in columns A to AN

When a condition in C is met, I want to add that row to an existing table (Table1), but ONLY certain columns (non-contiguous) as the rest of the data is superfluous, and the table has already been "cleaned" of this data.

The way I thought about doing this was to loop backwards through C, test for the condition, then when my condition is met, add the partial row to Table1.

I have existing code that does most of this, except its copying and pasting the row to a range, not a table.

To keep it short, instead of copying the row to the next blank slot on a sheet, I need help with the VBA that handles Tables.

I know how to create an extra row for my existing table, just not add parts of a row to that table.

Thanks
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Two sites I frequent for table how-to
You'll want to see the last part on Inserting rows and columns in the second one.
 
Upvote 1
Two sites I frequent for table how-to
You'll want to see the last part on Inserting rows and columns in the second one.
Thanks for this,

After some research I've used the below

VBA Code:
                Set newRow = Table1.ListRows.Add()
                    With newRow
                        .Range(1) = sTasks.Range("A" & r).Value
                        .Range(2) = sTasks.Range("B" & r).Value
                        .Range(3) = sTasks.Range("U" & r).Value
                        .Range(4) = sTasks.Range("V" & r).Value
                        .Range(5) = sTasks.Range("W" & r).Value
                        .Range(6) = sTasks.Range("X" & r).Value
                        .Range(7) = sTasks.Range("Y" & r).Value
                        .Range(8) = sTasks.Range("Z" & r).Value
                        .Range(9) = sTasks.Range("AA" & r).Value
                        .Range(10) = sTasks.Range("AB" & r).Value
                        .Range(11) = sTasks.Range("AC" & r).Value
                        .Range(12) = sTasks.Range("AD" & r).Value
                        .Range(13) = sTasks.Range("AE" & r).Value
                        .Range(14) = sTasks.Range("AF" & r).Value
                        .Range(15) = sTasks.Range("AG" & r).Value
                        .Range(16) = sTasks.Range("AH" & r).Value
                        .Range(17) = sTasks.Range("AI" & r).Value
                        .Range(18) = sTasks.Range("AJ" & r).Value
                        .Range(19) = sTasks.Range("AK" & r).Value
                        .Range(20) = sTasks.Range("AL" & r).Value
                        .Range(21) = sTasks.Range("AM" & r).Value
                    End With

Which is contained within an IF statement for the condition/s I mentioned in the original post. It's quite long-winded, but I imagine it's possible to use .Range(i) and loop through the table ranges that way... not sure how I'd go about making the .value portion neater though.

What you've helped me with works perfectly by the way, so thank you, I'm just thinking for future improvements
 
Upvote 0
The code you posted can be reduced to this by using the contiguous parts together
VBA Code:
                Set newRow = Table1.ListRows.Add()
                    With newRow
                        .Range(1).Resize(, 2).Value = sTasks.Range("A" & r).Resize(, 2).Value
                        .Range(3).Resize(, 19).Value = sTasks.Range("U" & r).Resize(, 19).Value
                    End With
 
Upvote 0

Forum statistics

Threads
1,215,094
Messages
6,123,071
Members
449,092
Latest member
ipruravindra

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