Sub oproepen vanuit andere sub

Status
Niet open voor verdere reacties.

asperoni

Nieuwe gebruiker
Lid geworden
10 jun 2007
Berichten
4
Goedemorgen,

Ik heb 2 subs gemaakt die een csv bestand omvormen naar text to columns (zijn beide net iets anders..)
nu wil ik een derde sub maken die moet gaan bepalen of sub 1 of sub 2 moet worden gebruikt. Het gaat om een csv bestand dat altijd zal beginnen met een T of met een H.

bv.
HO,8951054231,2252522335,20100331
HO,blablabla

of

TR,89510234343,2237322344,20100305
TR,blablabla


De sub die ik nu heb (en niet werkt) is
Sub Decide()

If Left(A1, 1) = "T" Then
Call TextToColumnsT
ElseIf Left(A1, 1) = "H" Then
Call TextToColumnsH
End If

End Sub



Kan iemand mij helpen? Alvast bedankt.
 
Daar heb je geen aparte macro's voor nodig: bijv.

Code:
Sub keus()
  If Left[COLOR="Red"]([A1], [/COLOR]1) = "T" Then
     sheets(1).columns(1).Texttocolumns , 1, -4142, , False, True, 
  Else
     sheets(1).columns(1).Texttocolumns , 1, -4142, , False, False, False, False, True, "|"
  End If
End Sub
 
Laatst bewerkt:
Op zich hoef ik daar geen aparte macro's voor te maken nee... maar het ziet er dan wel overzichtelijker uit.
Ik heb jou manier geprobeerd, maar ook deze pakt hij niet... het lijkt erop alsof het gedeelte: If Left(A1, 1) = "T" Then niet herkend wordt (hij geeft nu dus de message box "werkt niet" weer als ik de macro run.

Code:
Sub SelectorAmazing()

'
' Decides whether it is a Transaction File or Holding File
'
' Keyboard Shortcut: Ctrl+Shift+D
'

    If Left(A1, 1) = "H" Then
                    Columns("A:A").Select
                    Selection.TextToColumns Destination:=Range("A1"), DataType:=xlDelimited, _
                        TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
                        Semicolon:=False, Comma:=True, Space:=False, Other:=False, FieldInfo _
                        :=Array(Array(1, 1), Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1), _
                        Array(7, 1), Array(8, 1), Array(9, 1), Array(10, 1), Array(11, 1), Array(12, 1)), _
                        TrailingMinusNumbers:=True
                    Cells.Select
                    Cells.EntireColumn.AutoFit
                    Rows("1:1").Select
                    Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
                    Range("A1").Select
                    ActiveCell.FormulaR1C1 = "Rec Type"
                    Range("B1").Select
                    ActiveCell.FormulaR1C1 = "Port Code"
                    Range("C1").Select
                    ActiveCell.FormulaR1C1 = "Sec Code"
                    Range("D1").Select
                    ActiveCell.FormulaR1C1 = "Date"
                    Range("E1").Select
                    ActiveCell.FormulaR1C1 = "Curr"
                    Range("F1").Select
                    ActiveCell.FormulaR1C1 = "Nominal"
                    Range("G1").Select
                    ActiveCell.FormulaR1C1 = "Base MV"
                    Range("H1").Select
                    ActiveCell.FormulaR1C1 = "Base BV"
                    Range("I1").Select
                    ActiveCell.FormulaR1C1 = "Base Acc"
                    Range("J1").Select
                    ActiveCell.FormulaR1C1 = "Local MV"
                    Range("K1").Select
                    ActiveCell.FormulaR1C1 = "Local BV"
                    Range("L1").Select
                    ActiveCell.FormulaR1C1 = "Local Acc"
                    Range("A1:L1").Select
                    Selection.Font.Bold = True
                    Cells.Select
                    Cells.EntireColumn.AutoFit
                    ActiveWindow.Zoom = 85
                    Range("A1:L1").Select
                    Selection.AutoFilter
                    Rows("2:2").Select
                    ActiveWindow.FreezePanes = True
    ElseIf Left(A1, 1) = "T" Then
                    Columns("A:A").Select
                    Selection.TextToColumns Destination:=Range("A1"), DataType:=xlDelimited, _
                        TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
                        Semicolon:=False, Comma:=True, Space:=False, Other:=False, FieldInfo _
                        :=Array(Array(1, 1), Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1), _
                        Array(7, 1), Array(8, 1), Array(9, 1), Array(10, 1), Array(11, 1), Array(12, 1)), _
                        TrailingMinusNumbers:=True
                    Cells.Select
                    Cells.EntireColumn.AutoFit
                    Rows("1:1").Select
                    Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
                    Range("A1").Select
                    ActiveCell.FormulaR1C1 = "Rec Type"
                    Range("B1").Select
                    ActiveCell.FormulaR1C1 = "Port Code"
                    Range("C1").Select
                    ActiveCell.FormulaR1C1 = "Sec Code"
                    Range("D1").Select
                    ActiveCell.FormulaR1C1 = "Tr Date"
                    Range("E1").Select
                    ActiveCell.FormulaR1C1 = "Tr Type"
                    Range("F1").Select
                    ActiveCell.FormulaR1C1 = "Curr"
                    Range("G1").Select
                    ActiveCell.FormulaR1C1 = "Cash Sec ID"
                    Range("H1").Select
                    ActiveCell.FormulaR1C1 = "Nominal"
                    Range("I1").Select
                    ActiveCell.FormulaR1C1 = "Base Amnt"
                    Range("J1").Select
                    ActiveCell.FormulaR1C1 = "Base Inc Amnt"
                    Range("K1").Select
                    ActiveCell.FormulaR1C1 = "Base Cash Eff"
                    Range("L1").Select
                    ActiveCell.FormulaR1C1 = "Local Amnt"
                    Range("M1").Select
                    ActiveCell.FormulaR1C1 = "Local Inc Amnt"
                    Range("N1").Select
                    ActiveCell.FormulaR1C1 = "Local Cash Eff"
                    Range("A1:N1").Select
                    Selection.Font.Bold = True
                    Cells.Select
                    Cells.EntireColumn.AutoFit
                    ActiveWindow.Zoom = 85
                    Range("A1:N1").Select
                    Selection.AutoFilter
                    Rows("2:2").Select
                    ActiveWindow.FreezePanes = True
    Else: MsgBox "Werkt Niet"
    End If
    
End Sub
 
Natuurlijk doet ie het niet. Zie mijn aangepaste vorige suggestie.

Jij gebruikt in beide gevallen dezelfde critera voor tekst naar kolommen. Daarvoor is de test overbodig.

PS. Als overzichtelijkheid een criterium is, kan er nog veel aan jouw code verbeterd worden. Hoe minder macro's, hoe overzichtelijker. Deze macro doet hetzlfde als de jouwe:

Code:
Sub simpel()
  Columns(1).TextToColumns , 1, -4142, , True,False, True, False, False
  Columns.autofit
  Rows(1).Insert 
  Cells(1,1).resize(,14)=split(iif(Left([A1],1)="T","Rec Type|Port Code|Sec Code|Date|Curr|Nominal|Base MV|Base BV|Base Acc|Local MV|Local BV|Local Acc||","Rec Type|Port Code|Sec Code|Tr Date|Tr Type|Curr|Cash Sec ID|Nominal|Base Amnt|Base Inc Amnt|Base Cash Eff|Local Amnt|Local Inc Amnt|Local Cash Eff"),"|")
  Range("A1:N1").Font.Bold = True
  Rows(2).Select
  ActiveWindow.FreezePanes = True
End Sub
 
Laatst bewerkt:
Tnx... hij werkt. Ik zag jou brackets niet --> [A1]:o

Jouw macro is inderdaad een stuk korter, maar op sommige stukken al bijna niet meer te begrijpen voor mij (helaas).
Ik weet gewoon te weinig af van macro's. (heb ook de opname functie gebruikt om de macro te maken... en dan kan ik de macro nog wel volgen in VBA).

Nogmaals bednakt!:thumb:
 
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan