Column Variable not Working

jmcvay

New Member
Joined
Aug 23, 2024
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Hi, I'm using variable for row and column in 2 different lines of code. But only the row varaible works; the column variable doesn't and I can't figure out why.

VBA Code:
partNum = Range("$B" & comRow).Text
comCat = Range(comCol & "$5").Text

Both variable are dimmed as integers. I thought there might be R1C1 issue, but I've tried referring that way too and it still won't work.

Any thoughts?

Thanks, jmac
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Range uses the letter of the column, not the number.

you can try:
comCat = Cells(5, comCol).value

Also I'd use .Value instead of .Text. Not sure if that would have an affect as well.
 
Upvote 0
Jeez, something as simple as getting my row and column backwards; can't see the forest for the trees sometimes. Thanks; appreciate the help. Working like a charm now.
 
Upvote 0
Jeez, something as simple as getting my row and column backwards; can't see the forest for the trees sometimes. Thanks; appreciate the help. Working like a charm now.
No, it wasn't that at all.

With Range(...), it is always column first, and row second (and column reference ALWAYS must be alpha).
With Cells(...), it is always row first and column second, separated by a comma (and the column reference can be alpha or numeric).

So it depends on which one you use. Cells is more flexible, in that it allows you to use column numbers instead of column letters.
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

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