Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

code go end current

Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Code to go to end of current data rather than to a specific row

Code to go to end of current data rather than to a specific row

ResolvedVersion 2003

Samantha has attended:
Excel VBA Intro Intermediate course

Code to go to end of current data rather than to a specific row

I have a master worksheet that is kept on one drive and i need users to be able to view certain parts of it in a different drive. I don't want to keep updating two worksheets so have written the follwoing code, which works, however the file size is 20mb which i think is quite large and not sure why.

The master data currently stands at 1896 rows which is why i've written the code to go to row 2000, was thinking, at present, the fact that the code will still be looking at rows 1897 to 2000, even though they are blank, may be a waste and if i can amend this it may reduce the file sizxe a bit?

In row 1 on the user sheet i have just put '=master sheet a1', so the code is just copying this formulae down (currently to row 2000), could this be making it large too?

Private Sub Workbook_Open()

Application.ScreenUpdating = False

With Worksheets("Open Codes")

.Unprotect Password:="melon"

.Range("2:2000").Clear

.Range("1:1").AutoFill .Range("1:2000")

.Range("2:2000").Font.Bold = False
.Range("b2:b2000").HorizontalAlignment = xlCenter
.Range("d2:d2000").HorizontalAlignment = xlCenter
.Range("f2:f2000").HorizontalAlignment = xlCenter
.Range("h2:h2000").HorizontalAlignment = xlCenter
.Range("j2:j2000").HorizontalAlignment = xlCenter

.Range("1:1").Select

Selection.AutoFilter

.Range("a1").Select

Selection.AutoFilter Field:=1, Criteria1:="Open"

Columns("A:AW").EntireColumn.AutoFit
Columns("m:aw").Hidden = True

Range("a1").Select

.Protect Password:="melon", AllowFiltering:=True

End With

End Sub

RE: code to go to end of current data rather than to a specific

Hi Samantha

Thanks for your question

I can see nothing in the code that is making your file size particularly large.
How many worksheets are there in the file, and typically how many rows? Does the file contain many charts, and/or other drawing objects?

Thanks

Stephen

RE: code to go to end of current data rather than to a specific

Hi Stephen

That's the thing that's weird - it's only one worksheet, no charts or drawing objects - the actual source file is huge too but thats because it's directly linked to lots of different workbooks.

Typically there is about the 1800 number of rows and columns got to AW.

 

Training courses

Training information:

Welcome. Please choose your application (eg. Excel) and then post your question.

Our Microsoft Qualified trainers will then respond within 24 hours (working days).

Frequently Asked Questions
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.

Excel tip:

Change the Print button so it brings up the Print dialogue box

If you want to bring up the Print dialogue box to check your print settings when you hit the Print button, do the following:

1. Right-click on the toolbar that displays the Print button.

2. Select Customise.

3. Click on the Print button on the toolbar to select it, then hold the left mouse button down and drag the button towards the screen below. The button should come off the toolbar.

4. In the Customise dialogue box on your screen, select the Commands tab.

5. Select File from the Categories list, and then locate the Print... icon (looks like the normal Print button, but the word Print has three dots following it).

6. Click on the Print... icon to select it, then use your left mouse to drag and drop the icon onto the toolbar at the top of the screen.

7. Close the Customise dialogue box.

View all Excel hints and tips

Connect with us:

0207 987 3777

Call for assistance

Request Callback

We will call you back

Server loaded in 0.1 secs.