+ Reply to Thread
Results 1 to 19 of 19

VBA Combining two macros (Find Next and Auto Caps)

  1. #1
    Forum Contributor
    Join Date
    02-19-2013
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    110

    VBA Combining two macros (Find Next and Auto Caps)

    Hello everyone,

    I'm trying to combine the below two macros into one.
    Basically the Find next macro is a box i created in the spreadsheet to find the word within the spreadsheet (To avoid 'Ctrl + F' all the time).

    They are both completely different macros but for the same sheet.

    Thank you!


    Find Next Macro

    Option Explicit
    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim rng As Range
    If Target.Address <> "$C$1" Then Exit Sub
    Set rng = Cells.Find(What:=Target.Value, After:=Target, LookIn:=xlValues, LookAt:=xlPart)
    If rng Is Nothing Then GoTo NotFound
    If rng.Address = Target.Address Then GoTo NotFound
    rng.Activate
    Exit Sub
    NotFound:
    MsgBox "Not found!", vbOKOnly, "Search for '" & Target.Value & "'"
    End Sub



    Auto Caps Macro

    Private Sub Worksheet_Change(ByVal Target As Range)
    If Intersect(Target, Range("B14:AJ1000")) Is Nothing Then Exit Sub
    Application.EnableEvents = False
    Target = UCase(Target)
    Application.EnableEvents = True
    End Sub

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: VBA Combining two macros (Find Next and Auto Caps)

    Maybe:

    Please Login or Register  to view this content.
    Last edited by xladept; 09-23-2013 at 07:02 PM.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  3. #3
    Forum Contributor
    Join Date
    02-19-2013
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    110

    Re: VBA Combining two macros (Find Next and Auto Caps)

    I'm getting the following Error when I try to input anything in the Search box: "Run-time error '91' Object variable or With block variable not set"

    And

    I'm getting the following Error when I try to put any letters within the range mentioned above to see if it'll auto caps: "Run-time error '13': Type mismatch".

    Thank you,

  4. #4
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: VBA Combining two macros (Find Next and Auto Caps)

    Wow - I only copied your code - can you post a sample that fails??

  5. #5
    Forum Contributor
    Join Date
    02-19-2013
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    110

    Re: VBA Combining two macros (Find Next and Auto Caps)

    TEST1.xlsm

    Yes for sure, please see the attachment.

    Thanks.

  6. #6
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: VBA Combining two macros (Find Next and Auto Caps)

    It seems to be working now:

    Please Login or Register  to view this content.

  7. #7
    Forum Contributor
    Join Date
    02-19-2013
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    110

    Re: VBA Combining two macros (Find Next and Auto Caps)

    Thank you so much! It worked!

  8. #8
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: VBA Combining two macros (Find Next and Auto Caps)

    You're welcome! But, I thought of an improvement - switch the End If:Exit Sub

    Please Login or Register  to view this content.

  9. #9
    Forum Contributor
    Join Date
    02-19-2013
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    110

    Re: VBA Combining two macros (Find Next and Auto Caps)

    One last thing,

    Now every time I delete any data (like a name or the blank search box) I get a Run-Time error 91: Object Variable or with block variable not set and it leads me to this If Intersect(Target, Range("I14:AJ1000")) <> "" Then

    Can you please help me out with this?

    Thanks.

  10. #10
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: VBA Combining two macros (Find Next and Auto Caps)

    Try this:

    Please Login or Register  to view this content.

  11. #11
    Forum Contributor
    Join Date
    02-19-2013
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    110

    Re: VBA Combining two macros (Find Next and Auto Caps)

    Thank you Xladept. The search box is fixed, it's not giving errors and the only thing left is the Name column (Column A), when i try to delete a name it's still giving that error.

  12. #12
    Forum Contributor
    Join Date
    02-19-2013
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    110

    Re: VBA Combining two macros (Find Next and Auto Caps)

    Attached is the updated spreadsheet where I'm having issue.

    If Target.Row>13 Then | Fixed the issue for the search box

    If only there was something similar for the column, so it can capture everything other than column A.
    Attached Files Attached Files

  13. #13
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: VBA Combining two macros (Find Next and Auto Caps)

    I changed the Intersect verbiage and it works now??

    Please Login or Register  to view this content.

  14. #14
    Forum Contributor
    Join Date
    02-19-2013
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    110

    Re: VBA Combining two macros (Find Next and Auto Caps)

    Can't seem to get it to work so I moved around some cells and the way I display, it seems to be fine now. However I don't need the range to be uppercase now, I only need from A15:A1000 to be uppercase, rest i gave up on and with the changes i made - i do not need them anymore.

    For that change I tried to change your code like this but it didn't work, it's giving errors:

    If Not Intersect(Range("A15:A1000"), Target) Is Nothing Then
    Target = UCase(Target): End If: Exit Sub

  15. #15
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: VBA Combining two macros (Find Next and Auto Caps)

    Weird - it works all the time for me now?

    Can you post the new sample??

  16. #16
    Forum Contributor
    Join Date
    02-19-2013
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    110

    Re: VBA Combining two macros (Find Next and Auto Caps)

    Test3.xlsm

    Yes for sure, here is the attachment, i cut down some of it because it exceeds the allowable size. Since everything other than column A is numbers, the uppercase should only be for column A.

    Thank you again.

  17. #17
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: VBA Combining two macros (Find Next and Auto Caps)

    Here's the new code:

    Please Login or Register  to view this content.

  18. #18
    Forum Contributor
    Join Date
    02-19-2013
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    110

    Re: VBA Combining two macros (Find Next and Auto Caps)

    Dude, you are seriously amazing! Thank you so much!

  19. #19
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: VBA Combining two macros (Find Next and Auto Caps)

    Your welcome!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Auto format time with : in Col A and Force Caps in Col D on Woksheet_change
    By Gingermuppet in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-27-2013, 05:22 AM
  2. 3 Simple Macros to toggle Num/Caps/Scroll
    By phillips321 in forum Excel General
    Replies: 0
    Last Post: 08-26-2011, 06:13 AM
  3. [SOLVED] How can I convert all Caps to first letter caps in Excel?
    By in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 09-06-2005, 06:05 AM
  4. [SOLVED] How can I convert all Caps to first letter caps in Excel?
    By Fenljp26 in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 01:05 AM
  5. [SOLVED] How can I convert all Caps to first letter caps in Excel?
    By Fenljp26 in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 12:05 AM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1