Help cleaning up some code if you please

EssKayKay

Active Member
Joined
Jan 5, 2003
Messages
354
Office Version
  1. 2007
Platform
  1. Windows
Hello,
This is no biggie here - really just wondering if there is a more efficient way to code this (my programming skills are very limited to say the least).

I have three routines that basically do the same thing to three sets of cells. I simply copied the code from the first set; then edit it for the next two. It appears to be doing what I want. However, I suspect there is a better way to achieve this.

I don’t expect anyone to spend much time on this but if it looks easy enough to clean up, I would be interested.

Here’s my code –
VBA Code:
‘- - - 1st One-Time - - -
     If Range("K8:K9").Locked = False And Range("K9") = "" Then
          MsgBox " Missing One-Time Amount" & vbNewLine & " Re-enter Payment details.", , " One-Time Pmt."
          Range("K8,K9").Select
          Selection.ClearContents
          Range("K9").Select
          Selection.Locked = True
          With Selection.Interior
              .Color = 15984868
         End With
         Range("K8").Select
         Exit Sub
End If


‘- - - 2nd One-Time - - -
     If Range("K10:K11").Locked = False And Range("K11") = "" Then
          MsgBox " Missing One-Time Amount" & vbNewLine & " Re-enter Payment details.", , " One-Time Pmt."
          Range("K10,K11").Select
          Selection.ClearContents
          Range("K11").Select
          Selection.Locked = True
          With Selection.Interior
              .Color = 15984868
          End With
          Range("K10").Select
          Exit Sub
     End If

‘- - - 3rd One-Time - - -
     If Range("K12:K13").Locked = False And Range("K13") = "" Then
          MsgBox " Missing One-Time Amount" & vbNewLine & " Re-enter Payment details.", , " One-Time Pmt."
          Range("K12,K13").Select
          Selection.ClearContents
          Range("K13").Select
          Selection.Locked = True
          With Selection.Interior
              .Color = 15984868
          End With
          Range("K12").Select
     Exit Sub
End If

Thanks for viewing,
Steve
 
EssKayKay,

When marking a post as the solution, please mark the original post that actually contains the solution, not your own post acknowledging that some other post is the solution.
So please mark the reply that best answered your question. Thank you.
OOPS, I thought I did that - my bad. There were actually two answers that worked perfectly.

Thanks Joe for the input. I promise, I will be more careful in the future (this old guy just keeps screwing up). . .
Steve K.
 
Upvote 0

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.

Forum statistics

Threads
1,220,965
Messages
6,157,120
Members
451,399
Latest member
alchavar

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