Hello to everybody,
Havent been on here in a while. Have a slight problem(at least i suspect it is) which i would like some help with:
I have a macro thatopens a userform on which a button is clicked to copy and paste data into sheets 2 and 3 of the excel control worksheet. Right after that a RUN button is clicked after making either a single or multiple selection of criteria from a listbox which then opens several destination folders to which data copied into sheets 2 and 3 of contol worksheets is in turn copied and distributed to the respective destination worksheets specified in the listbox selection.Here is the code underlying the RUN button.
My code stops at the
"If lstRegions.Selected(i) = True Then" line
Public Sub Create_Click()
Dim i As Integer, intRow As Integer
Dim fs, a, b
Dim blnfail As Boolean
Dim strTradRegion As String, strRetRegion As String
Set fs = CreateObject("Scripting.FileSystemObject")
'Assigns a value for the objects, in this case the folders
'determined to the following variables
'The macro will later test the value, if true the folder exists
'and the macro will continue, if false an error message will
'appear stating that destination folder does not exist in the
'assigned path
strTradRegion = Workbooks("Trading Accounts.xls").Sheets("Control").Range("M3")
strRetRegion = Workbooks("Trading Accounts.xls").Sheets("Control").Range("M4")
a = fs.folderexists(txtPath & strTradRegion)
b = fs.folderexists(txtPath & strRetRegion)
Workbooks("Trading Accounts.xls").Sheets("Control").Range("J2:K20").Clear
intRow = 2
i = 0
If cbValidate.Value = True Then Call validation(blnfail)
If blnfail = True Then Exit Sub
Do While Range("F" & i + 2) = "" = False
If lstRegions.Selected(i) = True Then ---------> macro stops at this line
Range("J" & intRow) = Range("G" & i + 2)
Range("K" & intRow) = Range("H" & i + 2)
intRow = intRow + 1
End If
i = i + 1
Loop
If Trading_Accs.Value = True And Retail_Reps.Value And cbClose = True Then
If b = False Then
MsgBox ("Could not find folder 'Trading Accounts' from path ") & txtPath, vbCritical
Exit Sub
End If
By_Region
Retail_Regions
Save
ElseIf Trading_Accs.Value And Retail_Reps.Value = True Then
If b = False Then
MsgBox ("Could not find folder 'Trading Accounts' from path ") & txtPath, vbCritical
Exit Sub
End If
By_Region
Retail_Regions
ElseIf Trading_Accs.Value And cbClose.Value = True Then
If b = False Then
MsgBox ("Could not find folder 'Trading Accounts' from path ") & txtPath, vbCritical
Exit Sub
End If
By_Region
Save
ElseIf Retail_Reps.Value And cbClose.Value = True Then
If a = False Then
MsgBox ("Could not find folder 'Retail Reports' from path ") & txtPath, vbCritical
Exit Sub
End If
Retail_Regions
Save
ElseIf Trading_Accs.Value = True Then
If b = False Then
MsgBox ("Could not find folder 'Trading Accounts' from path ") & txtPath, vbCritical
Exit Sub
End If
By_Region
ElseIf Retail_Reps.Value = True Then
If a = False Then
MsgBox ("Could not find folder 'Retail Reports' from path ") & txtPath, vbCritical
Exit Sub
End If
Retail_Regions
Else
MsgBox ("Please select at least one option"), vbCritical
End If
Trad_Accs.Hide
End Sub
I suspect that it has something to do with my boolean variables.I must pt out that when i first click on the first button (with a seperate code) to copy and paste data into sheets 2 and 3 and close the form ,then open again and click on the RUN button, it runs perfectly.
However the problem arises when i decide to subsequently click the RUN button after the first button has been clicked.
Appreciate all help, Thanks
romij29
Havent been on here in a while. Have a slight problem(at least i suspect it is) which i would like some help with:
I have a macro thatopens a userform on which a button is clicked to copy and paste data into sheets 2 and 3 of the excel control worksheet. Right after that a RUN button is clicked after making either a single or multiple selection of criteria from a listbox which then opens several destination folders to which data copied into sheets 2 and 3 of contol worksheets is in turn copied and distributed to the respective destination worksheets specified in the listbox selection.Here is the code underlying the RUN button.
My code stops at the
"If lstRegions.Selected(i) = True Then" line
Public Sub Create_Click()
Dim i As Integer, intRow As Integer
Dim fs, a, b
Dim blnfail As Boolean
Dim strTradRegion As String, strRetRegion As String
Set fs = CreateObject("Scripting.FileSystemObject")
'Assigns a value for the objects, in this case the folders
'determined to the following variables
'The macro will later test the value, if true the folder exists
'and the macro will continue, if false an error message will
'appear stating that destination folder does not exist in the
'assigned path
strTradRegion = Workbooks("Trading Accounts.xls").Sheets("Control").Range("M3")
strRetRegion = Workbooks("Trading Accounts.xls").Sheets("Control").Range("M4")
a = fs.folderexists(txtPath & strTradRegion)
b = fs.folderexists(txtPath & strRetRegion)
Workbooks("Trading Accounts.xls").Sheets("Control").Range("J2:K20").Clear
intRow = 2
i = 0
If cbValidate.Value = True Then Call validation(blnfail)
If blnfail = True Then Exit Sub
Do While Range("F" & i + 2) = "" = False
If lstRegions.Selected(i) = True Then ---------> macro stops at this line
Range("J" & intRow) = Range("G" & i + 2)
Range("K" & intRow) = Range("H" & i + 2)
intRow = intRow + 1
End If
i = i + 1
Loop
If Trading_Accs.Value = True And Retail_Reps.Value And cbClose = True Then
If b = False Then
MsgBox ("Could not find folder 'Trading Accounts' from path ") & txtPath, vbCritical
Exit Sub
End If
By_Region
Retail_Regions
Save
ElseIf Trading_Accs.Value And Retail_Reps.Value = True Then
If b = False Then
MsgBox ("Could not find folder 'Trading Accounts' from path ") & txtPath, vbCritical
Exit Sub
End If
By_Region
Retail_Regions
ElseIf Trading_Accs.Value And cbClose.Value = True Then
If b = False Then
MsgBox ("Could not find folder 'Trading Accounts' from path ") & txtPath, vbCritical
Exit Sub
End If
By_Region
Save
ElseIf Retail_Reps.Value And cbClose.Value = True Then
If a = False Then
MsgBox ("Could not find folder 'Retail Reports' from path ") & txtPath, vbCritical
Exit Sub
End If
Retail_Regions
Save
ElseIf Trading_Accs.Value = True Then
If b = False Then
MsgBox ("Could not find folder 'Trading Accounts' from path ") & txtPath, vbCritical
Exit Sub
End If
By_Region
ElseIf Retail_Reps.Value = True Then
If a = False Then
MsgBox ("Could not find folder 'Retail Reports' from path ") & txtPath, vbCritical
Exit Sub
End If
Retail_Regions
Else
MsgBox ("Please select at least one option"), vbCritical
End If
Trad_Accs.Hide
End Sub
I suspect that it has something to do with my boolean variables.I must pt out that when i first click on the first button (with a seperate code) to copy and paste data into sheets 2 and 3 and close the form ,then open again and click on the RUN button, it runs perfectly.
However the problem arises when i decide to subsequently click the RUN button after the first button has been clicked.
Appreciate all help, Thanks
romij29