| Excel - Ερωτήσεις / Απαντήσεις Ότι έχει σχέση με συναρτήσεις, μορφοποίηση, εκτυπώσεις γραφήματα κτλ. |
![]() |
| | Εργαλεία Θεμάτων | Τρόποι εμφάνισης |
| |
|
#1
| |||
| |||
|
Καλησπέρα Χρησιμοποιώ την ακόλουθη VBA για την εύρεση ονόματος. Στην περίπτωση που δεν υπάρχει το όνομα μου δίνει σφάλμα 91. Θα παρακαλούσα κάποια βοήθεια. Ευχαριστώ εκ των προτέρων. Κώδικας: 'Attribute VB_Name = "FindText"
Sub FindText()
Dim i As Long
Dim Fnd As String
Dim fCell As Range
Dim ws As Worksheet
Dim Color As Long
Dim rngCurr As Range
Fnd = InputBox("Enter text to search" & vbCr & vbCr _
& "Click OK to search the entire workbook for all instances of the search text." & _
" Each instance will be highlighted. This search is not case-sensitive, but it will not" & _
" locate search text if its cell contains other text, including a formula.")
If Fnd = vbNullString Then
Exit Sub
End If
Application.ScreenUpdating = False
Application.Dialogs(xlDialogPatterns).Show 'shows color palette
Color = ActiveCell.Interior.Color 'stores index number of selected color
ActiveCell.Interior.Color = xlNone
'since previous line colors cell where cursor pointer is, this removes the shading from that cell
Application.ScreenUpdating = True
Cells.Find(What:=Fnd, After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).Activate
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = Color
.TintAndShade = 0
.PatternTintAndShade = 0
End With
first_pos = ActiveCell.Address 'first cell found
Cells.FindNext(After:=ActiveCell).Activate 'find the next cell if any
While ActiveCell.Address <> first_pos 'while nect cell is not the first one
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = Color
.TintAndShade = 0
.PatternTintAndShade = 0
End With
Cells.FindNext(After:=ActiveCell).Activate
Wend
End Sub
Τελευταία επεξεργασία από το χρήστη Tasos : 29-10-11 στις 23:43. Αιτία: Ρύθμιση πλάτους πλαισίου κώδικα |
|
#2
| ||||
| ||||
|
Καλημέρα Θανάση! Επειδή τα Activate που περιέχονται στον κώδικα δεν είναι ότι γρηγορότερο, σου προτείνω τον παρακάτω κώδικα που χρωματίζει τα κελιά που περιέχουν το κριτήριο αναζήτησης. Κώδικας: Option Explicit
Sub ColorFoundCells()
Dim SearchString, FirstAddress As String, _
lColor As Long, OldColor As Long, rng As Range
SearchString = Application.InputBox("Enter text to search", Type:=2)
If SearchString = False Then Exit Sub
Set rng = Cells.Find(SearchString, LookIn:=xlValues)
If Not rng Is Nothing Then
FirstAddress = rng.Address
OldColor = IIf(ActiveCell.Interior.ColorIndex = xlNone, _
xlNone, ActiveCell.Interior.Color)
If Application.Dialogs(xlDialogPatterns).Show Then
lColor = ActiveCell.Interior.Color
ActiveCell.Interior.Color = OldColor
Else
Exit Sub
End If
Else
MsgBox "Search string not found!", vbInformation
Exit Sub
End If
Do
rng.Interior.Color = lColor
Set rng = Cells.FindNext(rng)
Loop While Not rng Is Nothing And rng.Address <> FirstAddress
End Sub
Το σφάλμα 91 το αποφεύγεις με τη γραμμή: If Not rng Is Nothing Then .... μετά από την αναζήτηση (Find ή FindNext). Φιλικά Τάσος
__________________ Ms-Office Development Team Ανάπτυξη επαγγελματικών εφαρμογών Τελευταία επεξεργασία από το χρήστη Tasos : 30-10-11 στις 01:54. |
|
#3
| |||
| |||
|
Τάσο καλημέρα, Όπως πάντα πρόθυμος και εξυπηρετικός με τις άριστες λύσεις όλων των προβλημάτων μας. Σε ευχαριστώ και σου εύχομαι καλή Κυριακή. Φιλικά Θανάσης |
![]() |
« Προηγούμενο Θέμα
|
Επόμενο Θέμα »
| |
| ||||
| Θέμα | Δημιουργός | Forum | Απαντήσεις | Τελευταίο Μήνυμα |
| [Excel07] Κατάργηση σύνδεσης κελιών στο Excel 2010 | George R | Excel - Ερωτήσεις / Απαντήσεις | 1 | 13-12-16 16:31 |
| [ Φόρμες ] στο Open της φορμας, Runtime error 2105 access 2010 | Dafnh0106 | Access - Ερωτήσεις / Απαντήσεις | 2 | 19-12-12 10:05 |
| [Συναρτήσεις] Υπολογισμός due date στο excel 2010 και μηδενισμός της ειδοποίησης | Kostas K | Excel - Ερωτήσεις / Απαντήσεις | 2 | 07-09-12 14:15 |
| [Excel07] Δημιουργία αντιστοίχισης XML (Xml map) Excel 2007 - 2010 | Tasos | Excel samples - Χρήσιμα αρχεία & παραδείγματα | 0 | 16-06-12 12:15 |
| [Γενικά] EXCEL 2010 ΦΑΚΕΛΟΣ wzbabb | panda | Excel - Ερωτήσεις / Απαντήσεις | 2 | 31-12-10 09:50 |
Η ώρα είναι 20:26.


Υβριδικός τρόπος

