I'm trying to count the cell number of the first row (A1-D1) which is known as header and get that count as the counter.
As all the while find most of them using Usedrange to count the columns:
$headercolcount=($worksheet.UsedRange.Columns).count
But UsedRange will capture maximum count in the whole activesheet, which resulting not identical to the column count in first row if there is extra content data below the header.
I only wish to grab just the first row:
[
]
Update: For clearer view, here is an example. As 1F & 1G there are no value present, so the answer should be 5 as 1A-1E as it contains data. So how should I grab the 5 correctly?
[
]

$headercolcount = $worksheet.UsedRange.Rows(1).Columns.CountTheUsedRangeis always a rectangular area though, so$worksheet.UsedRange.Columns.Countwould be equivalent