2017-04-04 58 views
0

其公式I可以做到這一點。但vba我不知道代碼簡單的詞 A1 =「旋律紅Dragraon」VBA中的CellFind函數

我想找到文本「紅色」。如果發現「紅色」=是紅色。如何寫或興趣這

Range("A3").Select 
Cells.Find(What:="red", After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _ 
    xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _ 
    , SearchFormat:=False).Activate 

問題的確定問題範圍A1 =旋律紅Dragraon我想搜索文本範圍從A1「紅」,如果發現在範圍A1 A2紅色=你發現了巨大的

我想多姆我導出PDF舊代碼

Dim codebranch As String 
Dim branchname As String 
Dim lictype As String 
On Error GoTo errHandler 

lictype = Mid(Range("B5"), 48, 7) 

您發現great_All _003_Lumpini_03_04_60.pdf

的完整代碼的PDF這裏

Sub Button28_PDF() 
Dim wsA As Worksheet 
Dim wbA As Workbook 
Dim strTime As String 
Dim strName As String 
Dim strPath As String 
Dim strFile As String 
Dim strPathFile As String 
Dim myFile As Variant 
Dim codebranch As String 
Dim branchname As String 
Dim lictype As String 
On Error GoTo errHandler 


lictype = Mid(Range("B5"), 48, 7) 
codebranch = Left(Range("A1"), 3) 
branchname = Mid(Range("A1"), 7, 50) 
Set wbA = ActiveWorkbook 
Set wsA = ActiveSheet 
strTime = Format(Now(), "dd_mm_yy") 

'get active workbook folder, if saved 
strPath = wbA.Path 
If strPath = "" Then 
strPath = Application.DefaultFilePath 
End If 
strPath = strPath & "\" 

'replace spaces and periods in sheet name 
strName = Replace(wsA.Name, " ", "") 
strName = Replace(strName, ".", "_") 

'create default name for savng file 
strFile = lictype & "_" & codebranch & "_" & branchname & "_" & strTime & ".pdf" 
strPathFile = strPath & strFile 

'use can enter name and 
' select folder for file 
myFile = Application.GetSaveAsFilename _ 
(InitialFileName:=strPathFile, _ 
     FileFilter:="PDF Files (*.pdf), *.pdf", _ 
     Title:="Select Folder and FileName to save") 

'export to PDF if a folder was selected 
If myFile <> "False" Then 
    wsA.ExportAsFixedFormat _ 
     Type:=xlTypePDF, _ 
     Filename:=myFile, _ 
     Quality:=xlQualityStandard, _ 
     IncludeDocProperties:=True, _ 
     IgnorePrintAreas:=False, _ 
     OpenAfterPublish:=False 
     'confirmation message with file info 
    MsgBox "PDF file has been created: " _ 
     & vbCrLf _ 
     & myFile 
End If 

exitHandler: 
    Exit Sub 
errHandler: 
    MsgBox "Could not create PDF file" 
    Resume exitHandler 
End Sub 
+0

請給一些更多的細節(例子嗎?)你的目標 – user3598756

回答

0

事情是這樣的......

Dim Rng As Range 
'Range("A3").Select 
Set Rng = Cells.Find(What:="red", After:=Range("A3"), LookIn:=xlFormulas, LookAt:= _ 
    xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _ 
    , SearchFormat:=False) 
If Not Rng Is Nothing Then 
    'do whatever you want to do with Rng cell found 
End If