CountA different for page than when using in VBA

ungoliath

Board Regular
Joined
Oct 21, 2004
Messages
113
I'm trying to have a sorting macro that finds the range size by using the counta function. However when I run this code I get a value for counta of 1 but a value of 4 when I use it directly within excel.

Sub Macro1()
Dim counterx As Integer
Dim countery As Integer

Sheets("POC Information").Select
counterx = WorksheetFunction.CountA("i3:xfd3")
countery = WorksheetFunction.CountA("C:C") - 1


With ActiveWorkbook.Worksheets("POC Information").Sort
.SetRange Range("B3:L" & countery)
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub


Can anyone tell me what's going on?
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Try

Code:
counterx = WorksheetFunction.CountA(Range("i3:xfd3"))
countery = WorksheetFunction.CountA(Columns("C")) - 1
 
Upvote 0
I've got this but it's not working

Sub Macro1()
Dim counterx As Integer
Dim countery As Integer

Sheets("POC Information").Select
counterx = Application.WorksheetFunction.CountA(Range("i3:xfd3"))
countery = Application.WorksheetFunction.CountA(Columns("C:C")) - 1


With ActiveWorkbook.Worksheets("POC Information").Sort
.SetRange Range("R[3]C[2]:R[" & (countery + 3) & "]C[" & (counterx + 8) & "]")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub
 
Upvote 0
Possibly

Code:
.SetRange Range("R3C2:R[" & countery + 3 & "]C[" & counterx + 8 & "]")
 
Upvote 0
Thanks,

I tried that first but still wound up w/ errors. I did however read about the Cells command and was able to get it to work w/ this line of code.

.SetRange Range(Cells(3, 2), Cells(countery + 5, counterx + 8))
 
Upvote 0

Forum statistics

Threads
1,224,603
Messages
6,179,849
Members
452,948
Latest member
UsmanAli786

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