Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding columns count of a range

Tags:

excel

count

vba

Below is some Excel VBA code that is supposed to print the column count of the range that is specified in the string. I am getting an error in the Debug.Print section. What am I doing wrong?

Dim val1a As String
val1a = "A1:D1"

Dim Rng1 As Range

Debug.Print Rng1(var1a).Columns.Count  ' error here
like image 298
K17 Avatar asked Sep 28 '12 21:09

K17


2 Answers

Use

Range(var1a).Columns.Count
like image 54
chris neilsen Avatar answered Oct 21 '22 07:10

chris neilsen


The mistake you did was,

you declared 'val1a' but calling 'var1a'.

correct the typo and you'll be able to get that.

like image 45
Christopher Avatar answered Oct 21 '22 05:10

Christopher