title: Countif function in VBA that refers to a table column by name?
body: <p>I'm having as issue trying to refer to a table column name in a countif statement.  I have a table <code>TBL_Client1</code> with multiple column names.  I have three slicers that can be selected to narrow down my table to 1 row.  I'm using the first column <code>Visible</code> in the table to identify when the table has been selected down to one row. I'm Currently using this code on a button to trigger another button visibility.  It works but the table I have is dynamic and could use more and more rows.  How can I refer to the table column name instead of <code>a1:a1500</code></p>
  
  <pre><code>Private Sub CommandButton1_Click()
  Dim n As Integer
  n = Application.WorksheetFunction.CountIf(Range("a1:a1500"), "1")
  If (n) = 1 Then
  Sheets("clientlist").CommandButton2.Visible = True
  Else
  Sheets("clientlist").CommandButton2.Visible = False
  End If
  </code></pre>
  
  <p>I'm using this to make a button visible <code>CommandButton2</code>.  <code>CommandButton2</code> once visible executes a copy function that once again, I cant figure out how to reference a table column by name instead of referring to a row number.  The following is my next macro:</p>
  
  <pre><code>Sub update()
  A = Worksheets("clientlist").Cells(Rows.Count, 4).End(xlUp).Row
  For i = 5 To A
  If Worksheets("clientlist").Cells(i, 1).Value = "1" Then
      Worksheets("clientlist").Cells(i, 2).Copy
      b = Worksheets("contactlog").Cells(Rows.Count, 2).End(xlUp).Row
      Worksheets("clientlist").Paste 
  Destination:=Worksheets("contactlog").Cells(b + 1, 2)
      Worksheets("clientlist").Cells(i, 3).Copy
      Worksheets("contactlog").Cells(b + 1, 3).PasteSpecial 
  Paste:=xlPasteValues
      Application.CutCopyMode = False
      Worksheets("clientlist").Cells(10, 11).Copy
      Worksheets("contactlog").Cells(b + 1, 4).PasteSpecial 
  Paste:=xlPasteValues
      Application.CutCopyMode = False
      Worksheets("clientlist").Cells(i, 11).Copy
      Worksheets("clientlist").Paste 
  Destination:=Worksheets("contactlog").Cells(b + 1, 7)
      Worksheets("clientlist").Cells(i, 12).Copy
      Worksheets("clientlist").Paste 
  Destination:=Worksheets("contactlog").Cells(b + 1, 6)
      Worksheets("clientlist").Cells(i, 13).Copy
      Worksheets("clientlist").Paste 
  Destination:=Worksheets("contactlog").Cells(b + 1, 5)
      Worksheets("clientlist").Cells(3, 11).Copy
      Worksheets("clientlist").Paste 
  Destination:=Worksheets("contactlog").Cells(b + 1, 8)
      c = Worksheets("deals").Cells(Rows.Count, 2).End(xlUp).Row
      Worksheets("clientlist").Cells(10, 11).Copy
      Worksheets("deals").Cells(c + 1, 3).PasteSpecial Paste:=xlPasteValues
  </code></pre>
  
  <p>Finally, I'm using 2 buttons and visibility only because I cant figure out how to get a Macro to run continuously.  I've been searching through the web (especially StackOverflow) for about 2 weeks now and I'm getting close, but just not quite as Dynamic as I feel it could be.  Ultimately I would like the visibility of the button to be triggered anytime something is selected on a slicer.  I already tried the change and update but since the actual information on the table itself is not changing the code I've tried hasn't worked.  And I would like to copy/countif/paste referring to table column names instead of row numbers and column numbers.
  Thanks for reading!  </p>