SelRow = Right(ActiveCell.row,1)-5

Barney bull

New Member
Joined
Apr 21, 2024
Messages
3
Office Version
  1. 365
Platform
  1. Windows
Hi, I have some code that works fine for figures from 1to 9, but when I get to 0 it returns an error.
Example.
Sub verticaltabs()
Dim SelRow as long
Dim FirstRow as long
SelRow = Right(ActiveCell.Row,1) - 5
With sheet1
.Range(“65:144”).EntireRow.hidden = True
FirstRow = 65 + ((SelRow - 1) * 20)
.Range(FirstRow &”:”& FirstRow + 19).EntireRow.Hidden = False
.Range(“B3”).Value = SelRow +FirstRow

As mentioned earlier this formula works well until you get to a 0. Example 109 right most digit is 9 however when you have 110 the right most digit is a 0. How can I fix this issue can anyone help please
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
works fine for figures from 1to 9
Really ?

The first line below will generate a negative for 101, 102 & 110 and that will cause the line after it to error out.
Rich (BB code):
FirstRow = 65 + ((SelRow - 1) * 20)        ' This combined with Right(ActiveCell.Row,1) - 5 will be a negative row value for 101,102 & 110
.Range(FirstRow &”:”& FirstRow + 19).EntireRow.Hidden = False ' This will error out if FirstRow is negative.
 
Upvote 0

Forum statistics

Threads
1,224,969
Messages
6,182,077
Members
453,088
Latest member
Chaoxite

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