Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Adding to a VBA?

Posted on 2016-10-12
6
Medium Priority
?
121 Views
Last Modified: 2016-10-12
I have the following VBA that I want to add the exact same execution to, for cells B23 through O34. I am a complete newbie rookie to doing anything with these types of things ... but I do know the below works, and I just want to know how to add these cells to the same operation. Can you tell me how to it edit? Thanks so much in advance!:

Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Target, Range("A7:O34")) Is Nothing Then
        On Error GoTo FallThrough
        Application.EnableEvents = False
        Dim a As Range
        For Each a In Intersect(Target, Range("A7:O34"))
            If IsNumeric(a.Value) Then _
                If a.Value > 1 And a.Value Mod 100 < 60 And Int(a.Value / 100) < 24 Then _
                    a = TimeValue(Int(a.Value / 100) & ":" & Format(a.Value Mod 100, "00"))
        Next a
    End If
FallThrough:
    Application.EnableEvents = True
End Sub
0
Comment
Question by:Tim Jackoboice
  • 3
  • 3
6 Comments
 
LVL 33

Expert Comment

by:Subodh Tiwari (Neeraj)
ID: 41841312
Notice the Range mentioned in the following line of code...
If Not Intersect(Target, Range("A7:O34")) Is Nothing Then
The code will be effective for this range so if you want this code to work for the range B23:O34, change the range portion like this...
If Not Intersect(Target, Range("B23:O34")) Is Nothing Then
0
 

Author Comment

by:Tim Jackoboice
ID: 41841316
Hi Subodh. Thanks -- I should have added more detail.

I only want the cell ranges B7:O18 and also B23:O34 in this VBA.  (I do not want cells B19:O22 included.)

Thanks!
0
 

Author Comment

by:Tim Jackoboice
ID: 41841322
My question should have looked like this:


I have the following VBA I want to exclude cells A19:O22 from. How do I do this?

Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Target, Range("A7:O34")) Is Nothing Then
        On Error GoTo FallThrough
        Application.EnableEvents = False
        Dim a As Range
        For Each a In Intersect(Target, Range("A7:O34"))
            If IsNumeric(a.Value) Then _
                If a.Value > 1 And a.Value Mod 100 < 60 And Int(a.Value / 100) < 24 Then _
                    a = TimeValue(Int(a.Value / 100) & ":" & Format(a.Value Mod 100, "00"))
        Next a
    End If
FallThrough:
    Application.EnableEvents = True
End Sub
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 33

Accepted Solution

by:
Subodh Tiwari (Neeraj) earned 2000 total points
ID: 41841329
Change that line to this...
If Not Intersect(Target, Range("B7:O18,B23:O34")) Is Nothing Then
0
 

Author Closing Comment

by:Tim Jackoboice
ID: 41841333
Wow ... it was that easy. I told you I was a complete rookie newbie to VBAs!

Thank you!
0
 
LVL 33

Expert Comment

by:Subodh Tiwari (Neeraj)
ID: 41841334
Yes it was that easy. :)
You're welcome. Glad to help.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
If you need to forecast numbers -- typically for finance -- the Windows and Mac versions of Excel 2016 have a basket of tools to get the job done.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question