PDA

View Full Version : [SOLVED:] Trying to return Table Column rather than Sheet Column from Find method



JBSMichael
11-29-2018, 04:48 AM
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

NoSparks
11-29-2018, 08:09 AM
try


intPasteColumn = loDataTable.HeaderRowRange.Find(what:="Issue_Code", LookIn:=xlValues, lookat:=xlWhole).Column - loDataTable.Range.Column + 1

JBSMichael
11-29-2018, 09:05 AM
With thanks to NoSparks for the workaround, I sorted it:


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