Hello,
Was checking back to see if anyone had any ideas on this code for me.
Thanks
Jennifer
Hello,
Was checking back to see if anyone had any ideas on this code for me.
Thanks
Jennifer
To call another macro from the 1st macro is easy
Macro1 starts to run, calls macro2![]()
Sub Macro1() Call Macro2 if range("a1").value = 2 then call macro3 end if End Sub
after MAcro2 runs macro1 continues running from the next command after it called macro2
Note you do not need to use the word Call in front of the macro name
Please Read Forum Rules Before Posting
Wrap VBA code by selecting the code and clicking the # icon or Read This
How To Cross Post politely
Top Excel links for beginners to Experts
If you are pleased with a member's answer then use the Scales icon to rate it
If my reply has assistedor failed to assist you
I welcome your Feedback.
Thanks I see how that works but here is the code where I want to call the other Macro. I can call both my macros from another macro by themselves no problem. But for some reason it wont call the macro I have highlighted when I put the code in like this. Any thoughts???
![]()
Sub Test() Dim requiredCells As Variant Dim prompts As Variant Dim i As Long requiredCells = Array("a3", "d3", "h3", "k3") prompts = Array("Date", "Account Manager", "Warehouse From", "Warehouse To") For i = LBound(requiredCells) To UBound(requiredCells) If Range(requiredCells(i)).Value = vbNullString Then Range(requiredCells(i)).Value = userInput(prompts(i)) If Range(requiredCells(i)).Value = vbNullString Then Call Mail_workbook_Outlook_2 End If Next i End Sub Function userInput(promptString As Variant) As String Do userInput = Application.InputBox("You must enter a " & promptString, Type:=2) If userInput = "False" Then userInput = vbNullString: Exit Function Loop Until userInput <> vbNullString End Function
My first guess would be a requirement is not being met? In this section of your code you use the same "If" statement twice.
I would think that the string "If Range(requiredCells(i)).Value" is not evaluating to "vbNullString".![]()
For i = LBound(requiredCells) To UBound(requiredCells) If Range(requiredCells(i)).Value = vbNullString Then Range(requiredCells(i)).Value = userInput(prompts(i)) If Range(requiredCells(i)).Value = vbNullString Then Call Mail_workbook_Outlook_2 End If Next i
A second look I see that you reset your "If" satement to "If Range(requiredCells(i)).Value = userInput(prompts(i))", then the second "If" statement would not evaluate to "vbNullString" and the call statement would be ignored.
Last edited by Rick_Stanich; 04-23-2008 at 10:10 AM.
Regards
Rick
Win10, Office 365
I see what your saying this is how the code was originally written, I don't write very much VB code but have an understanding of how it works. It is set to exit the sub once it's finished checking all the cells for data. But what I need it to do is call the Email Macro so the excel file is then emailed out, that is where I am having the problem. I can't get it to go from this macro once its done with its routine to the email macro
Thanks
![]()
For i = LBound(requiredCells) To UBound(requiredCells) If Range(requiredCells(i)).Value = vbNullString Then Range(requiredCells(i)).Value = userInput(prompts(i)) If Range(requiredCells(i)).Value = vbNullString Then Exit Sub: Rem Cancel pressed End If Next i End Sub
Wooo hooo never mind my brain just exploded, I took out the second If statement and put in an else statement and NOW it works
Thanks for everyones help on this, sometimes it helps to have a few extra eyes and brain cells![]()
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks