How to find number of columns on a specific row using VBA in Excel

darioromero

New Member
Joined
Mar 21, 2008
Messages
2
I am creating a VBA code inside an excel spreadsheet. I would like to obtain from the "Sheet1" how many populated columns I have from every row when I traverse the "Sheet1" row by row.
What I have in the "Sheet1" are info like this:
Polygon x y x y x y X Y
P1 4 4 4 8 6 9
p2 6 7 5 2 8 8 9 10

I have tried this
MsgBox ("There exists " & XlPolygon.Sheet2.Range("R3C256").End(xlToRight).Count & " Columns in Row 3 on Sheet 2")

And some other ways I found in the web but no luck yet. :eek:
Could you please help me? Thanks.
Developer
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Something like this perhaps

Code:
Sub test()
Dim LastRow As Long, i As Long, LastCol As Integer
LastRow = Cells(Rows.Count, 1).End(xlUp).Row
For i = 1 To LastRow
    LastCol = Cells(i, Columns.Count).End(xlToLeft).Column
    MsgBox LastCol & " columns in row " & i
Next i
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,436
Messages
6,124,869
Members
449,192
Latest member
MoonDancer

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