Cleaning up some "Select" code

EssKayKay

Active Member
Joined
Jan 5, 2003
Messages
407
Office Version
  1. 2007
Platform
  1. Windows
Hello,
I’m asking for some suggestions here if you please.

I have been informed eliminating some "Select" commands may speed up VBA routines. I have numerous situations where I believe I could streamline my coding. Here are a few examples. If I can clean these up, I will work on the others.

Rich (BB code):
'#1 –
Range("K8,K9,K11:K13").Select
Selection.Locked = True
Selection.FormulaHidden = False
   With Selection.Interior
      .Color = 15984868
      .TintAndShade = 0
   End With

'#2 –
If Range("K8") > 0 And Range("K9") <= 0 Then
Range("K9").Select
Selection.Locked = False
Selection.FormulaHidden = False
   With Selection.Interior
      .Pattern = xlNone
      .TintAndShade = 0
   End With
End If

'#3 –
   Range("I33").Select
   Selection.Copy
   Range(Selection, Selection.End(xlDown)).Select
   ActiveSheet.Paste
   Application.CutCopyMode = False
   Range("M33:M" & Range("LastDataRow").Value).ClearContents
   Range("F6:F8,F10,K6:K13,F15:F17,F22").ClearContents

'#4 –
   Range("R34").Select
   Selection.Copy
   Range("R34:R133").Select
   ActiveSheet.Paste
   Application.CutCopyMode = False

'#5 –
   Range("P33:P" & Range("LastDataRow").Value).Select
   Selection.ClearContents
   Range("LookupFormula").Select
   Selection.Copy
   Range("P33").Select

Thanks for viewing,
Steve K.
 
This code shouldn't take long to run anyway. How long does it take, and what is your objective for performance?
 
Upvote 0

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
This is only a very small snipit of my entire project code. The entire coding involves over 1600 lines of code - of which I assume much of it is either redundant or sloppy. There are numerous calls throughout.

If you wish, I can post this. However, I suspect it may be a bit overwhelming as I noted, I am not a programmer so much of my code will simply amaze you, and not in a good way - but for the most party - it works.

Thank you both again for your time and consideration. It truly is appreciated.
Steve
 
Upvote 0
Yeah, 1600 is a fair amount for a VBA project. I don't recommend posting it here. However, if you find that you still need help with it, can you share your file with a cloud service like Dropbox, OneDrive, or Google Docs?
 
Upvote 0
I'm going to work on this a bit more. If I think I need more help (which is most always the case) I'll be back with a dropbox upload. I'll keep you posted.

Once again Jeff - thank you,
Steve
 
Upvote 0
What you can do is put a timer in the code, run it, notice the time, change all same type pieces of code run it again and see what the difference is.
 
Upvote 0
What you can do is put a timer in the code, run it, notice the time, change all same type pieces of code run it again and see what the difference is.
Good idea. I actually have a timer that can assist in that. I'll see what happens.
Thank you. . .
 
Upvote 0
Make sure to use a copy of your full original workbook. If something goes wrong, it's gone forever. No "undo" button for a macro.
 
Upvote 0
Make sure to use a copy of your full original workbook. If something goes wrong, it's gone forever. No "undo" button for a macro.
Yup, I've learned that the hard way - more than once.

Take care. . .
SKK
 
Upvote 0

Forum statistics

Threads
1,223,912
Messages
6,175,344
Members
452,638
Latest member
Oluwabukunmi

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