Excel VBA questions

arnabmit

New Member
Joined
Mar 28, 2009
Messages
23
Office Version
  1. 2019
  2. 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
 

Some videos you may like

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.

eduzs

Well-known Member
Joined
Jul 6, 2014
Messages
690
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
Like this: ?
VBA Code:
ShtName = "SheetName"
Debug.Print Application.CountA(Sheets(ShtName).Range("A:A"))
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
52,960
Office Version
  1. 365
Platform
  1. Windows
How about
VBA Code:
iRow = Evaluate("counta(" & ShtName & "!A:A)")
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,218
Office Version
  1. 365
Platform
  1. Windows
You can't use a variable with that syntax, try this.
VBA Code:
iRow = Application.CountA(Sheets(shtName).Range("A:A"))
 
Solution

arnabmit

New Member
Joined
Mar 28, 2009
Messages
23
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows

ADVERTISEMENT

Thanks all! Really helpful :)
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
52,960
Office Version
  1. 365
Platform
  1. Windows
Glad we could help & thanks for the feedback.
 

arnabmit

New Member
Joined
Mar 28, 2009
Messages
23
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
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?
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
52,960
Office Version
  1. 365
Platform
  1. Windows
Different questions need their own threads, so you will need to start a new thread for this question. Thanks
 

Watch MrExcel Video

Forum statistics

Threads
1,122,567
Messages
5,596,908
Members
414,110
Latest member
docops

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
Top