Excel VBA questions

arnabmit

New Member
Joined
Mar 28, 2009
Messages
27
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Hi,

I am trying to use the line

iRow = [COUNTA(Sheet1!A:A)]

But instead of Sheet1 I want to use a variable shtName

Please help me with the syntax
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Like this: ?
VBA Code:
ShtName = "SheetName"
Debug.Print Application.CountA(Sheets(ShtName).Range("A:A"))
 
Upvote 0
You can't use a variable with that syntax, try this.
VBA Code:
iRow = Application.CountA(Sheets(shtName).Range("A:A"))
 
Upvote 0
Solution
Glad we could help & thanks for the feedback.
 
Upvote 0
Another question please (Not sure if I should post all questions in a single thread, so as to not unnecessarily increase thread count, or in separate threads based on exact topic)

Note: ShtName is a public variable

VBA Code:
    Dim dbSheet As Worksheet
    Dim dbTable As ListObject

    Set dbSheet = ThisWorkbook.Sheets("Form")
    Set dbTable = ThisWorkbook.Sheets(ShtName).ListObjects(ShtName)


    ActiveSheet.lstPrev.RowSource = dbTable.DataBodyRange.Address(External:=True)

I am trying to get the content of a formatted table into an ActiveX list box lstPrev. I am getting error 438 "Object doesn't support this property or method".

What am I doing wrong?
 
Upvote 0
Different questions need their own threads, so you will need to start a new thread for this question. Thanks
 
Upvote 0

Forum statistics

Threads
1,213,513
Messages
6,114,072
Members
448,546
Latest member
KH Consulting

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