ItIsHardToProgram
Technical User
Hello all,
I currently am having a weird problem, wich I can't really define, I have passed almost an hour on this and I am totaly clueless.
I have a macro wich I am working on right now, that is suppose to collect data from a file to another, I am trying to optimize it a bit and working on it every day, so that it can be used for almost all data we hold in the cmopany, wich would save me alot of time.
What it does, is go look at opened workbooks name, splits the name, takes a company name, then matches it with a company name on another spreadsheet.
Once that is done, it goes look for the G/L account, in the spreadsheet.
Unfortunatly G/L accounts are never entered properly, but I can split the cell in order to get that G/L account.
So far so good.
I get the data I need and paste it.
Everything was working fine until I decided to place it in another sub, that I call from my primary sub.
I have a loop, for j = 3 to iworkbookcount
where iworkbookcount = 5
and it errors on j = 6 --> ??????????????
I do not add anything anywhere to the j, I thought it might have to do with the Resume Next in my error handler, but it does not...
I am really clueless.
Here is the code for the primary and the 2nd cell, + the global variables:
global variables
Now the primary macro
And the Merging sub
Sorry for the disorganized code but it wouldnt fit in my original settings.
Thank you for your help, as usual.
"Knowing that you know is the greatest sign of stupidity, knowing that you are ignorant is the best proof of intelligence.
I currently am having a weird problem, wich I can't really define, I have passed almost an hour on this and I am totaly clueless.
I have a macro wich I am working on right now, that is suppose to collect data from a file to another, I am trying to optimize it a bit and working on it every day, so that it can be used for almost all data we hold in the cmopany, wich would save me alot of time.
What it does, is go look at opened workbooks name, splits the name, takes a company name, then matches it with a company name on another spreadsheet.
Once that is done, it goes look for the G/L account, in the spreadsheet.
Unfortunatly G/L accounts are never entered properly, but I can split the cell in order to get that G/L account.
So far so good.
I get the data I need and paste it.
Everything was working fine until I decided to place it in another sub, that I call from my primary sub.
I have a loop, for j = 3 to iworkbookcount
where iworkbookcount = 5
and it errors on j = 6 --> ??????????????
I do not add anything anywhere to the j, I thought it might have to do with the Resume Next in my error handler, but it does not...
I am really clueless.
Here is the code for the primary and the 2nd cell, + the global variables:
global variables
Code:
Option Explicit
'
' WorkBookNavigation Macro
' Macro enregistrée le 08/07/2008 par Julien Roy
Dim iWorkBookCount, iSheetCount, RowCount As Integer
Dim iSheet, iRow, iBook As Integer
Dim i, y, row As Integer
Dim SheetName() As String
Dim location, name, company As String
Dim ActColumn As Integer
Dim FoundValue As Double
Dim testerror As Boolean
Dim currentworkbook, currentworksheet, currentrow, currentcolum As Integer
Dim SplitCompany() As String
Dim SplitGL, SplitGL2
Dim TempVal
Now the primary macro
Code:
Sub RedistributionGL()
'Merger entre feuille pour GL et compagnie
'Julien-Bono Roy, 25/11/2008
On Error Resume Next
iWorkBookCount = Workbooks.Count
row = 1
For i = 1 To 9
'Variable source pour le merger, compte de GL ou de compagnie
row = row + 1
SplitGL = Split(Cells(row, 2).Value, "-")
SplitGL = Split(SplitGL(0), " ")
row = row + 21
For y = 3 To 199
'Dépend des variables pour le merger... il est possible de storer les variables dans un tableau
'Pour que celles-ci soient utilisé dans un select case avec une boucle tableau(i)
Select Case i
Case 1
If y < 24 Then
Call Merging
End If
Case 2
'répétition du case 1
If y < 46 And y > 24 Then
Call Merging
End If
Case 3
If y < 68 And y > 46 Then
Call Merging
End If
Case 4
If y < 90 And y > 68 Then
Call Merging
End If
Case 5
If y < 112 And y > 90 Then
Call Merging
End If
Case 6
If y < 134 And y > 112 Then
Call Merging
End If
Case 7
If y < 156 And y > 134 Then
Call Merging
End If
Case 8
If y < 178 And y > 156 Then
Call Merging
End If
Case 9
If y < 200 And y > 178 Then
Call Merging
End If
End Select
Next y
Next i
End Sub
And the Merging sub
Code:
Sub Merging()
On Error GoTo ErrorHandler
Dim j, x As Integer
company = Cells(y, 1).Value
For j = 3 To iWorkBookCount
currentworkbook = j
SplitCompany = Split(Workbooks(j).name, "-")
If SplitCompany(0) = company Then
'MsgBox (SplitCompany(0))
'MsgBox (Company)
For x = 1 To 1000
If Workbooks(j).Worksheets(1).Cells(x, 2).FormulaR1C1 <> "" Then
name = Workbooks(j).Worksheets(1).Cells(x, 2).FormulaR1C1
SplitGL2 = Split(name, " ")
TempVal = SplitGL2(0)
'Ligne ou l'erreur survenait
If SplitGL2(0) = SplitGL(1) And Len(SplitGL2(0)) = 5 Then
'MsgBox (SplitGL2(0))
'MsgBox (SplitGL(1))
'MsgBox (x)
Range("E" & y & ":" & "P" & y).Select
Selection.Copy
Workbooks(j).Worksheets(1).Activate
Range("C" & x).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Workbooks("Copie de Classeur2.xls").Activate
End If
End If
Next x
End If
Next j
ErrorHandler:
name = Workbooks(currentworkbook).Worksheets(1).Cells(x, 2).FormulaR1C1 & " "
SplitGL2 = Split(name, " ")
Resume Next
End Sub
Sorry for the disorganized code but it wouldnt fit in my original settings.
Thank you for your help, as usual.
"Knowing that you know is the greatest sign of stupidity, knowing that you are ignorant is the best proof of intelligence.