Write existing short code another way to rule out column shift

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,596
Office Version
  1. 2007
Platform
  1. Windows
Currently using this code below but an odd thing keeps happening & now looking to get it written another way please to avoid it.

I select the POSTAGE sheet & it always scrolls so last row with values are shown, THIS IS FINE.
I like to have the cell in column B of last row with values selected.

Currently the odd thing is the page moves so column B is the firt column i see on the screen meaning column A is off the screen.
I change B in the code for E & it does the same where column E is the first column i see on the screen meaning column A,B,C & D are off the screen.

Dont see why the code cant just stay as it is & have the cell in column B selected.
Changing the Offset values just moves the selected cell down or right etc so maybe not needed but whatever i try its either the same or run time errors



VBA Code:
Private Sub Worksheet_Activate()
Application.Goto Sheets("POSTAGE").Range("B" & Rows.count).End(xlUp).Offset(0, 0), True
ActiveWindow.SmallScroll UP:=15
End Sub
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
The "True" at the end of your Goto line tells it to make that cell the top left hand corner of the screen.
Just remove the ", True"


1721046783895.png
 
Upvote 0
Doesnt seem to work for me,code in use is shown below.

I select the first sheet followed by POSTAGE sheet.
Last cell in column B is selected but A is off the page.

I select another sheet then POSTAGE sheet again & this time dont even see the last row.
This seems to be the same pattern as opposed to seeing the last row each time with cell B selected
VBA Code:
Private Sub Worksheet_Activate()
Application.Goto Sheets("POSTAGE").Range("B" & Rows.count).End(xlUp).Offset(0, 0)
ActiveWindow.SmallScroll UP:=15
End Sub
 
Upvote 0
The issue is that the POSTAGE page doesnt reset itself if that makes sense.
Thus the scroll up then does its job from where the last row shown on screen was at the time then does the scroll part
 
Upvote 0
So as a test ive used the code shown below.
Example i have a sheet called INVOICE & POSTAGE.
Currently the last row in view is row 2221
Each time i selectect INVOICE then POSTAGE the rows alter & drcease by .
So now my row in view is 2220
Do the same again & again & i see 2219, 2218, 2217

Without adding any new dtat to rows Shouldnt i come to the sheet POSTAGE & the code runs so i see the same row in view each time without it decreasing ?


VBA Code:
Private Sub Worksheet_Activate()
Range("B" & Cells.Rows.count).End(xlUp).Offset(0, 0).Select
ActiveWindow.SmallScroll UP:=1
 
Upvote 0
For your original request, try this
VBA Code:
Private Sub Worksheet_Activate()
' scroll sheet to have specified cell selected and at top left
Application.Goto Sheets("POSTAGE").Range("B" & Rows.Count).End(xlUp).Offset(0, -1), True
' offset from that specified cell to select desired cell
ActiveCell.Offset(, 1).Select
' scroll sheet to position row in view
ActiveWindow.SmallScroll UP:=15
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,398
Latest member
rjsteward

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