2 gedeclareerde waardes in EEN cel plaatsen (excel 2007)

Status
Niet open voor verdere reacties.

Fredemel

Gebruiker
Lid geworden
2 jun 2008
Berichten
123
Ik wil vanuit 2 macro's de gedeclareerde variabelen in een cel zetten.
De eerste variabele wordt binnen de macro gedeclareerd. De tweede var middels een MsgBox
De ampersand (&) werkt niet en ik weet niet waar ik het moet zoeken. Bvd
Code-1
Code:
Sub AIB()

Dim code As String
Dim ccode As String

ccode = "AIB-"

    ActiveCell.Range("A1:C1").Select
    With Selection.Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .Color = 255
        .TintAndShade = 0
        .PatternTintAndShade = 0
    End With
    ActiveCell.Offset(0, 1).Range("A1").Select
    With Selection.Font
        .ThemeColor = xlThemeColorDark1
        .TintAndShade = 0
    End With
    Application.Run "xCursus"
    ActiveCell.Offset(1, -1).Range("A1").Select
End Sub

Code-2
Code:
Sub xCursus()

Dim code As String
Dim ccode As String

    code = InputBox("Geef cursucode?" & vbCrLf & vbCrLf & "Wat is de cursus_omschrijving", _
    "Cursus_omschrijving", , myX, myY)
    ActiveCell.FormulaR1C1 = ccode & code
End Sub
 
Zoiets?
Code:
Sub AIB()
    With ActiveCell.Resize(, 3).Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .Color = 255
        .TintAndShade = 0
        .PatternTintAndShade = 0
    End With
    
    With ActiveCell.Offset(, 1).Font
        .ThemeColor = xlThemeColorDark1
        .TintAndShade = 0
     End With
    Application.Run "xCursus"
  Application.Goto ActiveCell.Offset(1)
End Sub

Code:
Sub xCursus()
 Dim code As String
 Dim ccode As String
 Dim myX, myY
 ccode = "AIB-"

    code = InputBox("Geef cursuscode?" & vbCrLf & vbCrLf & "Wat is de cursus_omschrijving", _
    "Cursus_omschrijving", , myX, myY)
    ActiveCell.Offset(, 1) = ccode & code
End Sub
Anders:
Code:
Option Explicit
Const ccode = "AIB -"
Code:
Sub AIB()
    With ActiveCell.Resize(, 3).Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .Color = 255
        .TintAndShade = 0
        .PatternTintAndShade = 0
    End With
    
    With ActiveCell.Offset(, 1).Font
        .ThemeColor = xlThemeColorDark1
        .TintAndShade = 0
     End With
    Application.Run "xCursus"
  Application.Goto ActiveCell.Offset(1)
End Sub
Code:
Sub xCursus()
 Dim code As String
 Dim myX, myY
   code = InputBox("Geef cursuscode?" & vbCrLf & vbCrLf & "Wat is de cursus_omschrijving", _
    "Cursus_omschrijving", , myX, myY)
    ActiveCell.Offset(, 1) = ccode & code
End Sub
 
Laatst bewerkt:
HSV, bedankt...!

Zowel de declaraties binnen de "Sub" als "Explicit" werken beide. Alleen snap ik daar nog effe nix van als beginner. Maar goed, het werkt en ik heb weer wat geleerd.
Ik wil me meer bekwamen in VBA. Weet je een goed beginnersboek....?
 
Ik wil me meer bekwamen in VBA. Weet je een goed beginnersboek....?

Kan ik je helaas niet aan helpen.
Ik heb er zelf nog nooit één ingekeken.

Met de Help van VBa en een paar forums kom je een heel eind mee weg.
 
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan