Consulting

Results 1 to 3 of 3

Thread: Trying to return Table Column rather than Sheet Column from Find method

  1. #1

    Trying to return Table Column rather than Sheet Column from Find method

    Hi. So I have a table on a sheet, and it starts in cell U1 (ie Row 1, Column 21). I am using the following section of code hoping that the first line will return 1, as the text "Issue_Code" is the column header in the first column in the loDataTable table. However, VB keeps returning intPasteColumn as 21, ie the sheet column number. Any idea what I'm doing wrong? I use a very similar procedure elsewhere and it works fine.

    Public wsCopySheet As Worksheet
    Public wsPasteSheet As Worksheet
    Public loDataTable As ListObject
    Public intCopyColumn As Integer
    Public intPasteColumn As Integer
    Public intCopyRow As Integer
    Public intPasteRow As Integer
    Public intStaticPasteRow As Integer
    
    Set wsCopySheet = wbRiskRegister.Sheets("Issue Log")
    Set wsPasteSheet = wbDataModel.Sheets("Risk-Issue Data")
    Set loDataTable = wsPasteSheet.ListObjects("Issue_Table")
    
    
    intPasteColumn = loDataTable.HeaderRowRange.Find(what:="Issue_Code", LookIn:=xlValues, lookat:=xlWhole).Column  'This is the offending lineintCopyColumn = wsCopySheet.Range("A2:AA3").Find(what:="Issue Code", LookIn:=xlValues, lookat:=xlWhole).Column
    wsCopySheet.Range(.Cells(intCopyRow, intCopyColumn), .Cells(intLastRow, intCopyColumn)).Copy
    loDataTable.Range.Cells(intStaticPasteRow, intPasteColumn).PasteSpecial Paste:=xlPasteValues

  2. #2
    VBAX Regular
    Joined
    Feb 2013
    Posts
    52
    Location
    try
    intPasteColumn = loDataTable.HeaderRowRange.Find(what:="Issue_Code", LookIn:=xlValues, lookat:=xlWhole).Column - loDataTable.Range.Column + 1

  3. #3

    Cracked it

    With thanks to NoSparks for the workaround, I sorted it:

    intPasteColumn = loDataTable.ListColumns("Issue_Code").Index

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •