Results 1 to 8 of 8

Thread: Simplifying Code

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #7
    VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,709
    Location
    Assigning a Range to a variable includes the sheet if present
    Set Rng = Sheets("Sheet1").Range("A1")
    Worksheet Code
    Set Rng = Sheet1.Cells(x,11)
    
    Select Case Rng.Value
       Case = "Update":   UpDate Rng
       Case = "Archive":  Archive Rng
       Case = "Refresh":  Refresh Rng
    End Select
    Sample Module Code Heads
    Sub Update(Rng As Range)
    '
    '
    '
    
    Sub Archive(Rng As Range)
    '
    '
    '
    To incorporate what Paul suggested as to consolidating all common factors
    Case = "Update"
       Common Rng
       Update Rng
    Case ' ' '
    '
    '
    '
    Sub Common(Rng As Range)
       With Rng
          .Offset(, 2) =Format(Now, "mm/dd/yyyy hh:mm:ss AM/PM")
          .Offset(, 3)= Format(.Offset(, 2) - .Offset(, 1), "[hh]:mm:ss")
       End With
    End Sub
    Last edited by SamT; 06-29-2022 at 06:26 AM.
    Please take the time to read the Forum FAQ

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •