Not copying first Column of table

sean1541

New Member
Joined
Feb 14, 2023
Messages
31
Office Version
  1. 2016
Platform
  1. MacOS
Hi this is the code i am using works apart from first column comes back blank
Sub AddDataToTable5()

Dim ws As Worksheet

Dim tbl6 As ListObject

Dim tbl5 As ListObject

Dim newRow As ListRow

Dim currentRow As ListRow

Dim colIndex As Long



' Set the worksheet

Set ws = ThisWorkbook.Sheets("Test Dry") ' Replace "Test Dry" with the actual sheet name



' Set Table 6

Set tbl6 = ws.ListObjects("Table6") ' Replace "Table6" with the actual name of Table 6



' Set Table 5

Set tbl5 = ws.ListObjects("Table5") ' Replace "Table5" with the actual name of Table 5



' Set the current row in Table 6 (assuming you want to use the last row)

Set currentRow = tbl6.ListRows(tbl6.ListRows.Count)



' Add a new row to Table 5

Set newRow = tbl5.ListRows.Add



' Copy values from cells B10 to H10 to the new row in Table 5

For colIndex = 2 To 8 ' Columns B to H

' Copy values

newRow.Range(1, colIndex - 0).Value = ws.Range("B10:H10").Cells(1, colIndex).Value

Next colIndex



' Copy font properties and alignment from Table 6 to the new row in Table 5

For colIndex = 1 To tbl6.ListColumns.Count

' Copy font properties

newRow.Range(1, colIndex).Font.FontStyle = currentRow.Range(1, colIndex).Font.FontStyle

newRow.Range(1, colIndex).Font.Color = currentRow.Range(1, colIndex).Font.Color

newRow.Range(1, colIndex).Font.Size = currentRow.Range(1, colIndex).Font.Size



' Set horizontal alignment to center

newRow.Range(1, colIndex).HorizontalAlignment = currentRow.Range(1, colIndex).HorizontalAlignment

Next colIndex



' Clear cells G10:H10 in Table 6

ws.Range("G10:H10").ClearContents

End Sub


Any help would be great
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Hard to tell without any sample data.

Unsure if this is what is causing it, But you are not copying Column A per this:

VBA Code:
' Copy values from cells B10 to H10 to the new row in Table 5

For colIndex = 2 To 8 ' Columns B to H

' Copy values
 
Upvote 0
Solution

Forum statistics

Threads
1,215,123
Messages
6,123,181
Members
449,090
Latest member
bes000

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