Combine similar subs into one sub.

dfenton21

Board Regular
Joined
Jun 23, 2007
Messages
135
Hi,

I have a spreadsheet that is used to book people on training courses. I have a sub that runs an input box for the person’s name, and then adds that name to the first blank cell of a specified range.

However, I have about 20 training sessions, with one sheet per session. I want to avoid having 20 different subs. It is possible to specify that I want the sub to work with the specified range in the current worksheet.

To further complicate the situation, the specified range for the names could be different sizes for each worksheet, as the maximum number differs for each session. I could add a hidden column to identity the rows that can be used if needed.

Have you any ideas how to use one sub module for all worksheets.

Thanks.
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
The sub goes into a normal module and you can use activesheet to specify the current sheet. Alternatively, change your processing sub so that it accepts a range object as a parameter, then call it from each sheet, telling it which range to look at.
 
Upvote 0
Hi dfenton21,

You could add something like the following, assuming that you call the inputbox when the required sheet is active, and the names go into column A.

r = ActiveSheet.Range("A65536").End(xlUp).Row + 1
Cells(r, 1) = InputBox("Enter Name")

ColinKJ
 
Upvote 0
That's perfect, thanks.

As I said, I have a macro that adds the response from the input box to the first blank cell of a range (B2:B20). Is it possible to modify this to only include cells with x in the corresponding cell in column A, e.g. if x does not appear in each cell between A15:A20, it will add the response to B14 even if B15:B20 is blank. Hope this makes sense.

Thanks again.
 
Upvote 0
dfenton21,

I think this is what you want:

Code:
r = ActiveSheet.Range("B20").End(xlUp).Row + 1
If r > 14 And Cells(r, 1) <> "x" Then r = 14
Cells(r, 2) = InputBox("Enter Name")

ColinKJ
 
Upvote 0

Forum statistics

Threads
1,214,515
Messages
6,119,972
Members
448,933
Latest member
Bluedbw

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