Add Column to Excel Table (VBA) but only 1st row populates not entire row

shell_l_d

Board Regular
Joined
Jun 25, 2010
Messages
73
I have an Excel spreadsheet with Macros/VBA:
* runs several SQL queries from an external database
* populates worksheet(s) with SQL result(s)
* in each worksheet, select data & create a table

* add extra columns to most of these tables
* add calculated formulas to first row of these extra columns (which auto populates the entire row with the same formula)

The problem is that at least 2 of our South African employees whom run this Excel spreadsheet, don't get the auto population of the entire row of the tables extra columns, so only the first row is populated (eg: D1=header & D2=1st data row, D3 to D5=blank data rows, D6=total).

They are using Windows XP (V5.1) & MS Office Professional 2007.

Any ideas what could cause this please & how can I fix it?

Code extracts to create table:
Rich (BB code):
         Dim iLastCol As Integer, iLastRow As Integer, iPos  As Integer, iMaxWidth As Integer
         Dim sEndTable As String, sLastColRef As String,  sTblName As String
         Dim oRngCol As Object
 
8         With ActiveSheet
 
9             .Range("A2").Select
10            sTblName = "tbl" & .Name
 
             ' find position of entire table including  headings
12            iLastCol =  .Range("A1").End(xlToRight).Column
13            iLastRow = 1    ' default in case no  data
 
             ' Ignore possible Error '6 Overflow' if only  header exists (no data)
14            On Error Resume Next
15            iLastRow =  .Range("A1").End(xlDown).Row
16            On Error GoTo  Error_In_CreateTable
 
             ' extract the column letter from sEndTable  eg:  AB from "$AB$100"
17            sEndTable = .Cells(iLastRow,  iLastCol).Address
18            iPos = VBA.InStrRev(sEndTable, "$",  -1)
19            sLastColRef = VBA.Mid(sEndTable, 2, iPos -  2)
 
             ' Add table - ignore error if table already  exists
20            On Error Resume Next
21            .ListObjects.Add(xlSrcRange, Range("$A$1:"  & sEndTable), , xlYes).Name = sTblName
22            On Error GoTo  Error_In_CreateTable
 
             ' Tablestyle for new table (adds filtering,  colours & totals)
23            With .ListObjects(sTblName)
24                .TableStyle = "TableStyleMedium9"  '  blue
25                .ShowHeaders = True
26                .ShowTotals = True
27            End With
 
47        End With               
     ' ===== Exit Handler =====
Exit_CreateTable:
48        On Error Resume Next
         ' Release memory used by Objects
49        If Not oRngCol Is Nothing Then oRngCol =  Nothing
50        Exit Sub

Code extracts to add extra columns to table:
Rich (BB code):
  Dim iRow As Integer
        Dim iCol As  Integer
 
2         With  ThisWorkbook.Worksheets("WaitOnCust")
3              .Select
4              Range("tblWaitOnCust").Select
 
5             iRow =  1
6             iCol =  .Range("tblWaitOnCust").Columns.Count
 
            '  Headings
8             .Cells(iRow, iCol  + 1).Value = "Event Day"
9             .Cells(iRow, iCol  + 2).Value = "Change from Wait"
10            .Cells(iRow, iCol  + 3).Value = "Calc Wait"
11            .Cells(iRow, iCol  + 4).Value = "Calc Wait Final"
 
            '  Values
12            On Error Resume  Next
13            .Cells(iRow + 1,  iCol + 1).FormulaR1C1 = "=WEEKDAY(tblWaitOnCust[[#This Row],[Event  Date]],2)"              
16            .Cells(iRow + 1,  iCol + 4).FormulaR1C1 = "=IF(tblWaitOnCust[[#This Row],[Calc  Wait]]<0,0,tblWaitOnCust[[#This Row],[Calc Wait]])"
17            On Error GoTo  Error_In_ExtraWaitOnCust
 
            ' Totals  row
22             Range("tblWaitOnCust[[#Totals],[Calc Wait]]").FormulaR1C1 =  "=SUBTOTAL(109,[Calc Wait])"
23             Range("tblWaitOnCust[[#Totals],[Calc Wait Final]]").FormulaR1C1 =  "=SUBTOTAL(109,[Calc Wait Final])"
 
25        End  With
 
        ' ===== Exit Handler  =====
26        Exit  Sub
 
Last edited:

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Have your users disabled the autofill functionality? It's under Office Button|Excel Options| Proofing|AutoCorrect Options|Fill formulas in tables to create calculated columns.
 
Upvote 0

Forum statistics

Threads
1,215,377
Messages
6,124,598
Members
449,174
Latest member
chandan4057

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