• Privacywetgeving
    Het is bij Helpmij.nl niet toegestaan om persoonsgegevens in een voorbeeld te plaatsen. Alle voorbeelden die persoonsgegevens bevatten zullen zonder opgaaf van reden verwijderd worden. In de vraag zal specifiek vermeld moeten worden dat het om fictieve namen gaat.

Probleem met selectie maken

Status
Niet open voor verdere reacties.

Joost.van.Steeg

Gebruiker
Lid geworden
9 okt 2006
Berichten
138
Ik was van plan bij een selectie de borders te zetten. Ik gebruikte hierbij de volgende code:
(colNumber is in dit geval 33, maar varieert dus)
Code:
ActiveSheet(.Range(Cells(28, colNumber), Cells(58, colNumber))).Select
                        Selection.Borders(xlDiagonalDown).LineStyle = xlNone
                        Selection.Borders(xlDiagonalUp).LineStyle = xlNone
                        With Selection.Borders(xlEdgeLeft)
                            .LineStyle = xlContinuous
                            .Weight = xlThin
                            .ColorIndex = xlAutomatic
                        End With
                        With Selection.Borders(xlEdgeTop)
                            .LineStyle = xlContinuous
                            .Weight = xlThin
                            .ColorIndex = xlAutomatic
                        End With
                        With Selection.Borders(xlEdgeBottom)
                            .LineStyle = xlContinuous
                            .Weight = xlThin
                            .ColorIndex = xlAutomatic
                        End With
                        With Selection.Borders(xlEdgeRight)
                            .LineStyle = xlContinuous
                            .Weight = xlThin
                            .ColorIndex = xlAutomatic
                        End With
                        With Selection.Borders(xlInsideVertical)
                            .LineStyle = xlContinuous
                            .Weight = xlThin
                            .ColorIndex = xlAutomatic
                        End With
                        With Selection.Borders(xlInsideHorizontal)
                            .LineStyle = xlContinuous
                            .Weight = xlThin
                            .ColorIndex = xlAutomatic
                        End With
Dit geeft echter de foutmelding: Run time error 1004 "Application-defined or object-defined error"

De volgende code doet precies hetzelfde en werkt wel.
Heeft iemand enig idee waarom de bovenstaande code een foutmelding geeft ?
Code:
X = 57
              Do
                X = X + 1
               ActiveSheet.Cells(X, colNumber).Select
                        Selection.Borders(xlDiagonalDown).LineStyle = xlNone
                        Selection.Borders(xlDiagonalUp).LineStyle = xlNone
                        With Selection.Borders(xlEdgeLeft)
                            .LineStyle = xlContinuous
                            .Weight = xlThin
                            .ColorIndex = xlAutomatic
                        End With
                        With Selection.Borders(xlEdgeTop)
                            .LineStyle = xlContinuous
                            .Weight = xlThin
                            .ColorIndex = xlAutomatic
                        End With
                        With Selection.Borders(xlEdgeBottom)
                            .LineStyle = xlContinuous
                            .Weight = xlThin
                            .ColorIndex = xlAutomatic
                        End With
                        With Selection.Borders(xlEdgeRight)
                            .LineStyle = xlContinuous
                            .Weight = xlThin
                            .ColorIndex = xlAutomatic
                        End With
                Loop Until X = 58
 
Klopt dit

Code:
ActiveSheet(.Range(Cells(28, colNumber), Cells(58, colNumber))).Select

wel? Vooral de . achter het haakje (.
 
Dat had ik inderdaad ook al geprobeerd, maar dan geeft ie:
Invalid or unqualified reference


An identifier beginning with a period is valid only within a With block. This error has the following cause and solution:

The identifier begins with a period.
Complete the qualification of the identifier or remove the period.

For additional information
 
We moeten echt wel de volledige code zien om de fout aan te wijzen, vermoed ik.
 
Ik hoop dat ik je de code op deze wijze kan aanleveren. Het gehele bestand is namelijk redelijk groot en bevat daarnaast het een en ander aan vertrouwelijke informatie.

Code:
'------------------------------------------------------------
'De publieke variabelen
'------------------------------------------------------------
Public TypeOnthouden As String
Public EWZHOnthouden As String
Public TypeAantalOnthouden As Integer
Public EWZHAantalOnthouden As Integer
Public rowNumber As Integer
Public rowNumber2 As Integer
Public EigenFactuurNaam As String
Public colNumber As Integer



'------------------------------------------------------------
'Factuur bevestigen
'De gefactureerde types en extra werkzaamheden naar "productie Invoer" sturen
'------------------------------------------------------------
Private Sub cmdBevestigen_Click()

'Middels een boodschap vragen of de gebruiker zeker is
    msgBevestiging


'Controleren of er wel data is ingevoerd
If ActiveSheet.Cells(27, "A").Value = "" And ActiveSheet.Cells(38, "A").Value = "" Then
    MsgBox ("Er zijn types ingevoerd, noch extra werkzaamheden")
    Exit Sub
End If

'EWZH opnemen op het blad met de factuurtotalen via de sub
    EWZHFactuurTotalen

    
'Beveilig de:
    'range van de extra werkzaamheden
    'Verlegd - range
    'Datum - range
    'nota nummer - range
    Sheets(EigenFactuurNaam).Activate
    ActiveSheet.Unprotect
        ActiveSheet.Range("A38:B45").Select
        Selection.Locked = True
        ActiveSheet.Range("I53").Select
        Selection.Locked = True
        ActiveSheet.Range("C18:D18").Select
        Selection.Locked = True
        ActiveSheet.Range("C20").Select
        Selection.Locked = True
    
'Verwijder de buttons
    ActiveSheet.Shapes("cmdBevestigen").Select
        Selection.Delete
    ActiveSheet.Shapes("cmdShowEWZH").Select
        Selection.Delete
    ActiveSheet.Protect
End Sub

'Vragen of alles correct is ingevuld

Private Sub msgBevestiging()
    Dim Msg, Style, Title, Response
        Msg = "Weet u zeker dat de factuur volledig is ingevuld"    ' Define message.
        Style = vbYesNo + vbCritical    ' Define buttons.
        Title = "Controleer de invoer!"    ' Define title.


    Response = MsgBox(Msg, Style, Title)
        If Response = vbYes Then    ' User chose Yes.
            Exit Sub ' Perform some action.
        Else    ' User chose No.
             End ' Perform some action.
        End If
End Sub


'------------------------------------------------------------
'Sub voor het invoeren van de EWZH op het blad productie invoer
'------------------------------------------------------------


Private Sub EWZHFactuurTotalen()

   'Eerst zoeken naar de factuurKolom waarin de hoeveelheden moeten worden vermeld
   'deze kolom draagt de naam van de factuur
   
        Dim AantalSheets As Integer
        AantalSheets = Sheets.Count
            EigenFactuurNaam = Sheets(AantalSheets).Name
            MsgBox (EigenFactuurNaam)
  
    colNumber = 26 '=z
        Do
            colNumber = colNumber + 1
        Loop Until Worksheets("Productie Invoer").Cells(1, colNumber).Value = EigenFactuurNaam
            Sheets("Productie Invoer").Activate
            ActiveSheet.Cells(20, colNumber).Select
                'Rij 20: Opmaken.
                    
                    Selection.Value = EigenFactuurNaam
                    Selection.Interior.ColorIndex = 6
                    Selection.Borders(xlDiagonalDown).LineStyle = xlNone
                    Selection.Borders(xlDiagonalUp).LineStyle = xlNone
                        With Selection.Borders(xlEdgeLeft)
                            .LineStyle = xlContinuous
                            .Weight = xlMedium
                            .ColorIndex = xlAutomatic
                        End With
                        With Selection.Borders(xlEdgeTop)
                            .LineStyle = xlContinuous
                            .Weight = xlMedium
                            .ColorIndex = xlAutomatic
                        End With
                        With Selection.Borders(xlEdgeBottom)
                            .LineStyle = xlContinuous
                            .Weight = xlMedium
                            .ColorIndex = xlAutomatic
                        End With
                        With Selection.Borders(xlEdgeRight)
                            .LineStyle = xlContinuous
                            .Weight = xlMedium
                            .ColorIndex = xlAutomatic
                        End With
                        
                'Rij 27: Opmaken.
                    
            ActiveSheet.Cells(27, colNumber).Select
                    Selection.Value = "Gefact"
                    Selection.Font.Bold = True
                    Selection.Interior.ColorIndex = 36
                    Selection.Borders(xlDiagonalDown).LineStyle = xlNone
                    Selection.Borders(xlDiagonalUp).LineStyle = xlNone
                        With Selection.Borders(xlEdgeLeft)
                            .LineStyle = xlContinuous
                            .Weight = xlMedium
                            .ColorIndex = xlAutomatic
                        End With
                        With Selection.Borders(xlEdgeTop)
                            .LineStyle = xlContinuous
                            .Weight = xlMedium
                            .ColorIndex = xlAutomatic
                        End With
                        With Selection.Borders(xlEdgeBottom)
                            .LineStyle = xlContinuous
                            .Weight = xlMedium
                            .ColorIndex = xlAutomatic
                        End With
                        With Selection.Borders(xlEdgeRight)
                            .LineStyle = xlContinuous
                            .Weight = xlMedium
                            .ColorIndex = xlAutomatic
                        End With
    
    

    
                'Onderstaande rijen van grit voorzien
                
            'ActiveSheet(.Range(Cells(28, colNumber), Cells(58, colNumber))).Select
            ActiveSheet.Range(Cells(28, colNumber), Cells(58, colNumber)).Select
                        Selection.Borders(xlDiagonalDown).LineStyle = xlNone
                        Selection.Borders(xlDiagonalUp).LineStyle = xlNone
                        With Selection.Borders(xlEdgeLeft)
                            .LineStyle = xlContinuous
                            .Weight = xlThin
                            .ColorIndex = xlAutomatic
                        End With
                        With Selection.Borders(xlEdgeTop)
                            .LineStyle = xlContinuous
                            .Weight = xlThin
                            .ColorIndex = xlAutomatic
                        End With
                        With Selection.Borders(xlEdgeBottom)
                            .LineStyle = xlContinuous
                            .Weight = xlThin
                            .ColorIndex = xlAutomatic
                        End With
                        With Selection.Borders(xlEdgeRight)
                            .LineStyle = xlContinuous
                            .Weight = xlThin
                            .ColorIndex = xlAutomatic
                        End With
                        With Selection.Borders(xlInsideVertical)
                            .LineStyle = xlContinuous
                            .Weight = xlThin
                            .ColorIndex = xlAutomatic
                        End With
                        With Selection.Borders(xlInsideHorizontal)
                            .LineStyle = xlContinuous
                            .Weight = xlThin
                            .ColorIndex = xlAutomatic
                        End With
                        
    'Waarden doorvoeren op de factuur en bij gefactureerd
          
    rowNumber = 27 'rij waar bij productie invoer sheet de EWZH staan gesommeerd
    rowNumber2 = 37 'rij waar bij de nieuwe factuur sheet de types staan gesommeerd
    
        Do
            rowNumber2 = rowNumber2 + 1
                
                'Kijk in elke rij waarin de EWZH kunnen worden opgegeven of er EWZH staan vermeld
            If Worksheets(EigenFactuurNaam).Cells(rowNumber2, "A").Value <> "" Then
                Do
                    rowNumber = rowNumber + 1
                'zoek naar de rij op de sheet productie invoer die overeenkomt met de naam op de factuur
                    
                Loop Until Worksheets(EigenFactuurNaam).Cells(rowNumber2, "A").Value = Worksheets("Productie Invoer").Cells(rowNumber, "Q").Value
                
                'Plaats het aantal dat op de factuur wordt vermeld in de nieuwe factuurkolom
                    Worksheets("Productie Invoer").Cells(rowNumber, colNumber).Value = Worksheets(EigenFactuurNaam).Cells(rowNumber2, "B").Value
            End If
        Loop Until rowNumber2 = 45
 End Sub

'Via de knop de te factureren extra werkzaamheden laten zien

Private Sub cmdShowEWZH_Click()
frmExtraWerkzaamH.Show
End Sub
 
Gezien de lengte wordt dat iets voor vanavond of de komende dagen.
 
Als je alleen een lijn om je cel wil hebben is de volgende code een stuk kleiner en sneller:
Code:
Range("A1:A100").Borders.LineStyle = xlContinuous

of voor meerdere gegevens
Code:
        With Selection
            .Interior.ColorIndex = 6
            .Borders.LineStyle = xlContinuous
            .Borders.Weight = xlMedium
            .Borders.ColorIndex = xlAutomatic
        End With

Code:
                   Selection.Borders(xlDiagonalDown).LineStyle = xlNone
                    Selection.Borders(xlDiagonalUp).LineStyle = xlNone
kan er ook uit.

Probeer ook zoveel mogelijk select te vermijden.
vb.
Code:
ActiveSheet.Range("A38:B45").Locked = True
        ActiveSheet.Range("I53").Locked = True
        ActiveSheet.Range("C18:D18").Locked = True
        ActiveSheet.Range("C20").Locked = True

Wordt je code al eens stuk minder lang van en zeker sneller om door een ander door te kunnen lezen:)


Groet,
Ferenc
 
Laatst bewerkt:
Bedankt voor je opmerkingen... ik neem veel macro's op, en dat geeft lang niet altijd de beste code inderdaad. Ik zal alles nog eens een keertje doorlopen.

Maar ook
Code:
ActiveSheet.Range(Cells(28, colNumber), Cells(58, colNumber)).Borders.LineStyle = xlContinuous
geeft een foutmelding.
 
probeer eens:
Code:
    With ActiveSheet.Range(Cells(28, colNumber), Cells(58, colNumber))
        .Interior.ColorIndex = 6
        .Borders.LineStyle = xlContinuous
        .Borders.Weight = xlMedium
        .Borders.ColorIndex = xlAutomatic
    End With

heb hem zomaar gevuld met enig data ter indicatie.

onuitputtelijke bron van info (dit keer geen Wigi :)):
http://www.exceltip.com/exceltips.php?view=category&ID=204


Groet,
Ferenc
 
Laatst bewerkt:
Status
Niet open voor verdere reacties.
Steun Ons

Nieuwste berichten

Terug
Bovenaan Onderaan