Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 41
Default Recursive Sub Routine?

I have a question for you gurus out there!

I have a macro to import a text file, run some code and basically assign
item numbers to each part of sheet based on different cells values. When
first run, the macro prompts for a job number, and then creates a directory
for this job number. Because each job has multiple text files, at the end of
each run of the subroutine, i'm calling the "WallsPlus()" sub routine again.
The thing is, I don't want the user to be prompted to have to type in a job
number for every single text file (Sometimes 50+)

I have two ideas, neither of which I know how to implement.

1. I wanted to setup If strJobNumber = "" then prompt for the job number...
if strJobNumber < "" then don't ask for a job number. The problem here, i
believe, is that when the sub routine is recalled, the previous strJobNumber
is erased and is always set to ""

2. Import all the text files in one go. I don't see how this is a huge
possibility, simply because every way i have tried to import a new text file,
it opens a new workbook. And to create a macro to copy and paste a new
workbook into a previous workbook an unknown number of times seems rather
difficult and necessary.

If anyone has any ideas on how I can implement either of these solutions,
let me know, and if you want to see my code (although very crude, but working
none-the-less) let me know!

Thanks,

Derek

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 41
Default Recursive Sub Routine?

Thank you very much! Works exactly as desired! I very much appreciate it!
I have one more question regarding variables.

In another macro I use to sort by multiple categories and calculate
statistics uses a userform with 12 checkboxes. I was wondering if there was
a way to allow the status of these checkboxes to be accessed by other
subroutines to avoid having to do:

Call Sort(checkbox1, checkbox2, checkbox3...checkboxN) I have the function
working fine by passing the variables this way, but I thought it would be
easier in the future if there was a way to make variables available to all
subs. I saw something about this one time, something about a common
variable, but I haven't been able to find it since. I've tried playing with
the global, public, and private types, but had no luck! Thanks Rick!

Derek

"Rick Rothstein" wrote:

Inside the WallsPlus subroutine, declare the variable that holds the job
number as a Static String so that its value will survive successive call to
the subroutine and then just test to see if the variable's content is the
empty or not. For example, put the following in the code window for one of
your worksheets...

Sub TestJobNumber()
Static JobNumber As String
If JobNumber = "" Then
JobNumber = InputBox("What is the Job Number?")
End If
MsgBox "The Job Number is " & JobNumber
End Sub

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, _
Cancel As Boolean)
Cancel = True
TestJobNumber
End Sub

Now go to that worksheet and double click any cell. You will be prompted for
a Job Number. Type it in and hit the Enter key. Doing that will display the
Job Number back to you. Dismiss the dialog box. Now, double click any other
cell. This time, you will not be prompted for the Job Number; instead, the
Job Number you typed in earlier will be repeated back to you.

--
Rick (MVP - Excel)


"Derek Johansen" wrote in message
...
I have a question for you gurus out there!

I have a macro to import a text file, run some code and basically assign
item numbers to each part of sheet based on different cells values. When
first run, the macro prompts for a job number, and then creates a
directory
for this job number. Because each job has multiple text files, at the end
of
each run of the subroutine, i'm calling the "WallsPlus()" sub routine
again.
The thing is, I don't want the user to be prompted to have to type in a
job
number for every single text file (Sometimes 50+)

I have two ideas, neither of which I know how to implement.

1. I wanted to setup If strJobNumber = "" then prompt for the job
number...
if strJobNumber < "" then don't ask for a job number. The problem here,
i
believe, is that when the sub routine is recalled, the previous
strJobNumber
is erased and is always set to ""

2. Import all the text files in one go. I don't see how this is a huge
possibility, simply because every way i have tried to import a new text
file,
it opens a new workbook. And to create a macro to copy and paste a new
workbook into a previous workbook an unknown number of times seems rather
difficult and necessary.

If anyone has any ideas on how I can implement either of these solutions,
let me know, and if you want to see my code (although very crude, but
working
none-the-less) let me know!

Thanks,

Derek



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Recursive Functions...maybe busboy10 Excel Worksheet Functions 0 March 28th 11 09:46 PM
Recursive Sub Routine? Rick Rothstein Excel Programming 0 June 19th 09 02:55 PM
Is this a recursive problem? davegb Excel Programming 2 August 16th 06 07:53 PM
Recursive Code Myles[_68_] Excel Programming 1 August 13th 06 02:11 PM
Recursive Functio help BigBobbo Excel Worksheet Functions 1 May 10th 06 07:23 PM


All times are GMT +1. The time now is 05:00 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"