Help with repeating macro's

WIGG77

New Member
Joined
Jun 25, 2014
Messages
49
Hello,

First post here so brief introduction.
My name is Dave and I work for a UK based company who design and manufacture bespoke hand built wheelchairs.

I am by no means an Excel god and have only really been using the program for around 6 months.

I set out to create a simple workbook to track the wheelchairs through the various stages of our manufacture with a simple tick box system and a click button to confirm the chair is ready for despatch. When the button is clicked an email is created and sent to the relevant recipients with certain cells from the sheet copied into the body of the mail. I use the workbook as a shared file between 2 people.

So far so good.

I use 1 sheet for each week and after adding the next 6 weeks or so, with 35-40 lines on each week the workbook gets somewhat clunky and slow. Each click button is assigned a separate macro and I guess this could be the route of my problem. If I use this workbook with other Excel documents open which link to MS Project, I often get the white screen crash or a complete system lockup. I patched together the VBA from other code people had posted here and there on the internet and adapted it to suit my needs.

As the code just repeats is there a way to streamline it but still retain the ability the copy the correct cells into the email body? Is there a way to copy the same cells but using th row the button is on?

Any help or advise would be greatly appreciated.

Dave

(I wasnt sure of the best way to upload the book so added a link to the file from my Dropbox)


https://dl.dropboxusercontent.com/u/13653846/Prod Progress.xlsb
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Hi Dave and Welcome to MrExcel,

Here's a few suggestions that should make your workbook more streamlined and easier to maintain.

You mention getting system lockups and crashes when your workbook is open with other Excel workbooks linked to MS Project. External links, especially those with formulas can put heavy demands on the system. It's possible that the cause of your crashes lies in those other workbooks. The suggestions below should help, but they may not eliminate those problems.

1. In lieu of using ActiveX or Form Checkboxes (you have some of each), try using "Marlett Checkboxes" approach. That approach uses VBA to toggle font symbol characters to display either checkbox checked or checkbox unchecked.
This article on Ozgrid explains how to set this up with some example code.
Excel VBA: Tick Cell Upon Selection

2. As you suspected, there are better alternatives than having separate macros that are nearly identical for each button. Instead you can assign one Sub procedure to all those similar purpose buttons. That Sub can use Application.Caller to determine the location of the button that Called the Sub, then use that location to process the desired range of cells dynamically.

This thread has code examples using this approach.
http://www.mrexcel.com/forum/excel-...ow-relative-button-location-excel-2010-a.html

3. Your macros are stored in the ThisWorkbook module of your Workbook. It's a good practice to put this type of code in a Standard Code Module of your workbook, and limit code in the ThisWorkbook module to Event procedures that are triggered at the Workbook level (like your Sub Workbook_BeforeSave).

Just ask if you have any problems implementing those suggestions.
 
Last edited:
Upvote 0
Hey Jerry,

Firstly thank you for your reply.

I've implemented the 'Marlett Checkbox' approach and that has made a real difference.

Unfortunately thought I'm too much of a novice at this sort of thing to use the add/remove line approach to achieve what I want to do.
My thought process was instead of 'CopyInsertThisRow' I need to use the column range I want added to the email body. Then instead of using '.copy' I would add the code from my original to sent the mail.

It's so frustrating to see what you want to do but lack the coding skills to carry it out.

Thanks again
Dave



 
Upvote 0
For my 2 cents worth, I'd remove ALL the ready for despatch buttons and leave only 1.
That one would have an InputBox asking which chair is ready to send, the user selects the chair cell in column "B" and rest of your code would populate.
That'll get rid of a fair bit of code AND the buttons !
 
Upvote 0
Further to the above.
You could attach this macro to 1 button....and get rid of the Rest of the RFD macros AND the RFD Buttons
Code:
Sub MM1()
Dim ans As Range
Set ans = Application.InputBox("Which Chair is ready for Despatch, please Select a cell in Column B", "Chair Selection", Type:=8)
If MsgBox("Do you wish to mark " & ans & " as ready for despatch?", vbYesNo) = vbNo Then Exit Sub
   ActiveSheet.Range("A3:D3").Select
   ActiveWorkbook.EnvelopeVisible = True
   With ActiveSheet.MailEnvelope
      .Introduction = "This wheelchair has passed final inspection and is cleared for delivery."
      .Item.To = ""
      .Item.CC = ""
      .Item.Subject = ans & " / " & ans.Offset(, 1) & " is ready for despatch"
      .Item.Send
   End With
End Sub
 
Upvote 0
Hi Micheal,

Thanks for your reply.

Thats great and works really well. Only problem I can see with that method is that only using one button I cant link the 'Marked as ready' check box. This would get confusing as to what has been marked as ready and what hasn't.

Also is there a way to not add the border of the cells to the email?

Thanks
Dave

<tbody></tbody>
 
Upvote 0
You can still use the check box or Marlett for Ready fr Dist....just get rid of all the buttons and have one situated somewhere else on the page.
I know, change is a bit confusing, but beneficial in the end ...:LOL:
 
Upvote 0
Further to the above.
You could attach this macro to 1 button....and get rid of the Rest of the RFD macros AND the RFD Buttons
Code:
Sub MM1()
Dim ans As Range
Set ans = Application.InputBox("Which Chair is ready for Despatch, please Select a cell in Column B", "Chair Selection", Type:=8)
If MsgBox("Do you wish to mark " & ans & " as ready for despatch?", vbYesNo) = vbNo Then Exit Sub
   ActiveSheet.Range("A3:D3").Select
   ActiveWorkbook.EnvelopeVisible = True
   With ActiveSheet.MailEnvelope
      .Introduction = "This wheelchair has passed final inspection and is cleared for delivery."
      .Item.To = ""
      .Item.CC = ""
      .Item.Subject = ans & " / " & ans.Offset(, 1) & " is ready for despatch"
      .Item.Send
   End With
End Sub

Hi Michael,
I've been playing around with the above you posted and it is a much better way of doing things.
Only problem I'm having is the email body alway shows cells A3-D3 insead of cells A-D of whichever row is selected as ready with the input box.

Thanks you
Dave
 
Upvote 0
don't have EXcel at the moment....try
Code:
Sub MM1()
Dim ans As Range
Set ans = Application.InputBox("Which Chair is ready for Despatch, please Select a cell in Column B", "Chair Selection", Type:=8)
If MsgBox("Do you wish to mark " & ans & " as ready for despatch?", vbYesNo) = vbNo Then Exit Sub
   ans = ans.Address(False, False)
ans = ans.Offset(, -1).Address(False, False) & ":" & ans.Offset(, 2).Address(False, False)
   ActiveWorkbook.EnvelopeVisible = True
   With ActiveSheet.MailEnvelope
      .Introduction = "This wheelchair has passed final inspection and is cleared for delivery."
      .Item.To = ""
      .Item.CC = ""
      .Item.Subject = ans & " / " & ans.Offset(, 1) & " is ready for despatch"
      .Item.Send
   End With
End Sub
 
Upvote 0
Thanks for the lightening fast reply.

Unfortunately it doesn't work. It now changes the selected cell from the inputbox to 'H9:K9' which results in 'H9:K9' in the subject field & copies the whole sheet into the email body.
 
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,733
Members
448,987
Latest member
marion_davis

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