Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Excel Makro

Empfohlene Antworten

Veröffentlicht

Hallo zusammen,

ich habe ein Makro entworfen, welches bei Adresslieferung in Excel die Postleitzahl überprüft und ggf. eine "0" davor setzt, wenn es nur 4 Zeichen sind.

Mein Problem ist, dass ich das Makro so umgestalten muss damit es nicht immer die gleiche Spalte prüft und ändert sondern es soll immer die markierte Spalte prüfen.

Könnt ihr mir bitte helfen? Unten steht der Quelltext :)

LG

Sylon

Columns("H:H").Select

Selection.Insert Shift:=xlToRight

Columns("I:I").Select

Selection.Insert Shift:=xlToRight

Selection.Insert Shift:=xlToRight

Range("H2").Select

ActiveCell.FormulaR1C1 = "=LEN(RC[-1])"

Range("H2").Select

Selection.AutoFill Destination:=Range("H2:H206"), Type:=xlFillDefault

Range("H2:H206").Select

ActiveWindow.SmallScroll Down:=-204

Range("I2").Select

ActiveCell.FormulaR1C1 = "=IF(RC[-1]=4,""0""&RC[-2],RC[-2])"

Range("I2").Select

Selection.AutoFill Destination:=Range("I2:I206"), Type:=xlFillDefault

Range("I2:I206").Select

ActiveWindow.SmallScroll Down:=-225

Range("I2:I206").Select

Selection.Copy

Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

:=False, Transpose:=False

Columns("J:J").Select

Application.CutCopyMode = False

Selection.Delete Shift:=xlToLeft

Range("I1").Select

ActiveCell.FormulaR1C1 = "PLZ"

Columns("G:H").Select

Range("H1").Activate

Selection.Delete Shift:=xlToLeft

End Sub

Hallo,

weil man nicht sehen kann was da reinkopiert wird,

lässt sich die Frage schlecht beantworten.

Das Beispiel unten formatiert nach Rückfrage die ganze Spalte mit dem Sonderformat "Postleitzahl".

Vielleicht hilft es ja:


Sub PLZ_Fomat()

Dim lngSpalte As Long

'ganze Spalte als Postleitzahl formatieren


  lngSpalte = ActiveCell.Column

  Columns(lngSpalte).Select


  If MsgBox("Spalte " & lngSpalte & " als PLZ formatieren?", _

            vbQuestion + vbYesNoCancel, _

            "") = vbYes Then


    Columns(lngSpalte).NumberFormat = "00000"

  Else

    MsgBox "Keine Änderung vorgenommen.", , ""

  End If


End Sub

Gruß

Alfons

also die Spalte "PLZ" ist jeder Excel immer an einer anderen Stelle

bisher macht das Makro folgendes:

-fügt rechts neben der Spalte 2 neue ein

- in die erste kommt: =länge(z.B G2)

- in die zweite kommt: =wenn(H2=4;"0"&G2;G2)

- beide formeln werden bis Zeile 265 circa gezogen

jetzt brauche ich das makro so, dass es nicht immer auf die Spalte "G" angewendet wird sondern auf die Spalte, die ich markiert hab >.<

Vielleicht ist es so für dich / euch besser nachzuvollziehen.

LG

Sylon

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.