string variable showing assigned value from listobject.name as empty

osmejia

New Member
Joined
Nov 21, 2023
Messages
2
Office Version
  1. 365
  2. 2021
  3. 2019
Platform
  1. Windows
I'm trying to assign the name of a ListObject (a table) to a string variable, however the variable is showing empty value even though the listobject name does exist and is correctly identified:

'------------------------------------------------------------------------------
'0. Declaration and Initialization of Variables
'------------------------------------------------------------------------------
Dim wb As Workbook
Set wb = ThisWorkbook
Dim wsSheet As Worksheet

Dim dateMasterIP, dateCurrentIP As Date
dateMasterIP = Range("rngMasterIPDate").Value

Dim wsName, strDataMasterIP, strDataCurrentIP, strNewSheetName As String
strDataMasterIP = "tbIP" & Year(dateMasterIP)

Dim objTable As ListObject
Dim TestForTable As String
Dim rngTestCell As Range

Dim rngIPDates() As Variant
rngIPDates = Range("rngIPDates").Value

'------------------------------------------------------------------------------
'2. Procedure Module
'------------------------------------------------------------------------------
For Each wsSheet In Worksheets
wsName = wsSheet.Name

If Left(wsName, 2) = "IP" Then
Set wsSheet = wb.Worksheets(wsName)
Set objTable = wsSheet.ListObjects(1)

Dim dateInspection As Variant
For Each dateInspection In rngIPDates
If Year(dateInspection) = Right(wsName, 4) Then
strDataCurrentIP = objTable.Name
dateCurrentIP = CDate(dateInspection)
End If
Call DataAlignment(wb, strDataMasterIP, strDataCurrentIP, dateMasterIP, dateInspection)
Next dateInspection
End If
Next wsSheet

Srolling over the code, the objTable.Name shows the value "tbIP2018" however the strDataCurrentIP shows an empty value.
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Try change:

If Year(dateInspection) = Right(wsName, 4) Then

to:

If Year(dateInspection) = CLng(Right(wsName, 4)) Then
 
Upvote 0
Side note:

When you define variables as below:
VBA Code:
Dim wsName, strDataMasterIP, strDataCurrentIP, strNewSheetName As String

Only strNewSheetName has been specifically defined. The rest are defined but with no type.

You should define each item as a type as below:
VBA Code:
Dim wsName As String, strDataMasterIP As String, strDataCurrentIP As String, strNewSheetName As String
 
Upvote 0

Forum statistics

Threads
1,215,073
Messages
6,122,975
Members
449,095
Latest member
Mr Hughes

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