Live-Forum - Die aktuellen Beiträge
Anzeige
Archiv - Navigation
1584to1588
Aktuelles Verzeichnis
Verzeichnis Index
Übersicht Verzeichnisse
Vorheriger Thread
Rückwärts Blättern
Nächster Thread
Vorwärts blättern
Anzeige
HERBERS
Excel-Forum
20+ Jahre Excel-Kompetenz: Von Anwendern, für Anwender
Inhaltsverzeichnis

VBA Code optimieren

VBA Code optimieren
20.10.2017 15:17:37
Mario
Guten Tag
ich habe mir einen VBA Code geschrieben der only Leseberechtigte Excel User bei Dateneintragung "VF" "U" etc auf "AW" ändert, dieses passiert auf 12 Worksheets ( Jänner bis Februar [ 1-12 ]
der Code ist soweit ausführbar aber nicht gerade der schönste
bitte um hilfe wenn möglich möchte ich
- die 12 Worksheets in schleife setzten ( derzeit schreibe ich jede einzeln )
- Selection.Replace möchte ich auch gerne "VF" "U" usw in einer abfrage auf "AW" ändern
hier der derzeitige code:
Sub AlleBlaetterEinblenden()
Application.EnableCancelKey = xlDisabled
Dim sh As Worksheet
ThisWorkbook.Unprotect Password:="mario"
For Each sh In Sheets
sh.Visible = True
Next sh
ThisWorkbook.Protect Password:="mario"
If ActiveWorkbook.ReadOnly Then
Tabelle1.Select
Range("E6..BN39").Select
Selection.Replace What:="VF", Replacement:="AW", LookAt:=xlWhole
Selection.Replace What:="U", Replacement:="AW", LookAt:=xlWhole
Selection.Replace What:="K", Replacement:="AW", LookAt:=xlWhole
Selection.Replace What:="UP", Replacement:="AW", LookAt:=xlWhole
Selection.Replace What:="KK", Replacement:="AW", LookAt:=xlWhole
Selection.Replace What:="FE", Replacement:="AW", LookAt:=xlWhole
Selection.Replace What:="FK", Replacement:="AW", LookAt:=xlWhole
Selection.Replace What:="ZU", Replacement:="AW", LookAt:=xlWhole
Range("E6").Select
Tabelle2.Select
Range("E6..BN39").Select
Selection.Replace What:="VF", Replacement:="AW", LookAt:=xlWhole
Selection.Replace What:="U", Replacement:="AW", LookAt:=xlWhole
Selection.Replace What:="K", Replacement:="AW", LookAt:=xlWhole
Selection.Replace What:="UP", Replacement:="AW", LookAt:=xlWhole
Selection.Replace What:="KK", Replacement:="AW", LookAt:=xlWhole
Selection.Replace What:="FE", Replacement:="AW", LookAt:=xlWhole
Selection.Replace What:="FK", Replacement:="AW", LookAt:=xlWhole
Selection.Replace What:="ZU", Replacement:="AW", LookAt:=xlWhole
Range("E6").Select
Tabelle3.Select
,.....

7
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
AW: VBA Code optimieren
20.10.2017 15:37:35
yummi
Hallo Mario,
ungetestet, probier mal aus

Sub AlleBlaetterEinblenden()
Application.EnableCancelKey = xlDisabled
Dim sh As Worksheet
ThisWorkbook.Unprotect Password:="mario"
For Each sh In Sheets
sh.Visible = True
Next sh
ThisWorkbook.Protect Password:="mario"
For Each sh In Sheets
If sh.ReadOnly Then
with sh.Range("E6..BN39")
.Replace What:="VF", Replacement:="AW", LookAt:=xlWhole
.Replace What:="U", Replacement:="AW", LookAt:=xlWhole
.Replace What:="K", Replacement:="AW", LookAt:=xlWhole
.Replace What:="UP", Replacement:="AW", LookAt:=xlWhole
.Replace What:="KK", Replacement:="AW", LookAt:=xlWhole
.Replace What:="FE", Replacement:="AW", LookAt:=xlWhole
.Replace What:="FK", Replacement:="AW", LookAt:=xlWhole
.Replace What:="ZU", Replacement:="AW", LookAt:=xlWhole
end with
Next sh
end Sub
Gruß
yummi
Anzeige
AW: VBA Code optimieren
20.10.2017 16:35:54
Mario
Hey yummi !
danke für deine sehr schnelle Antwort !!
finde es echt super so tolle antworten zu erhalten
hoffe ich bin auch mal so gut um anderen Leuten so tolle Tipps geben zu können
lg und ein schönes Wochenende
Mario
AW: VBA Code optimieren
20.10.2017 15:47:15
Daniel
Hi
im Prinzip so.
bearbeitet werden die ersten 12 Blätter in der Liste

dim i as Long
dim Txt
for i = 1 to 12
With Worksheets(i).Range("E6:BN39")
for each Txt in Split("VF,U,K,UP,KK,FE,FK,ZU", ",")
.Replace Txt, "AW", lookat:=xlwhole
next Txt
end with
next i
Gruß Daniel
AW: VBA Code optimieren
20.10.2017 16:32:57
Mario
Grüße Daniel
Wow dein Code ist super toll !!!
sieht auf meine Laptop schon sehr gut aus
bin morgen auf die Arbeit gespannt ( PC ist viel schlechter ,aber ich denke durch den Code wird die Ausführung vieel schneller :)
großen Danke !!
lg und schönes Wochenende
Mario
Anzeige
AW: VBA Code optimieren
20.10.2017 15:49:43
ChrisL
Hi Mario
Hier noch ein Ansatz (nur Schleife ohne Drumherum). Ich gehe davon aus, die Blätter sind mit Januar, Februar etc. angeschrieben.
Sub t()
Dim i As Integer, ii As Integer
Dim ar As Variant: ar = Array("VF", "U", "K", "UP", "KK", "FE", "FK", "ZU")
For i = 1 To 12
With Worksheets(Format(DateSerial(2017, i, 1), "MMMM")).Range("E6:BN39")
For ii = 0 To UBound(ar)
.Replace What:=ar(ii), Replacement:="AW", LookAt:=xlWhole
Next ii
End With
Next i
End Sub
cu
Chris
AW: VBA Code optimieren
20.10.2017 16:30:12
Mario
hey Chris !
danke für deine schnelle Antwort
derzeit sind die Tabellen zwar erst in Jän , Feb ,.. benannt aber das ist ja das geringste Problem =)
herzlichen dank für deinen Tipp ! hoffe ich werde auch mal so gut in Excel ;)
lg und schönes Wochenende
Anzeige
AW: VBA Code optimieren
20.10.2017 17:11:52
ChrisL
Hi Mario
Danke für die Rückmeldung.
Der Vollständigkeit halber... Kannst auch Format "MMM" machen = Jan, Feb etc.
Mit dem Namen ansprechen hat den Vorteil, dass es auch funktioniert, wenn bei den Tabellen-Index-Nummern mal etwas durcheinander gerät. Nachteil: funktioniert nur mit deutschsprachigem Excel.
cu
Chris

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige