• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Select worksheet based on criteria

paradise

Member
Kindly edit 2nd line of a code as mentioned below code to add a condition to select

If worksheet "Data" A1 = format1 then select -Worksheets("format1").Copy
If worksheet "Data"A1=Format2 then select -Worksheets("format1").Copy
If worksheet "Data"A1=Format3 then select -Worksheets("format3").Copy
If worksheet "Data"A1=Format4 then select -Worksheets("format4").Copy

Code:
For i = 6 To lastRow
        Worksheets("format1").Copy after:=Worksheets(Worksheets.Count)
        With ActiveSheet
            wsName = Replace(Replace(Replace(Replace(Replace(Replace(Replace(wsName, ":", ""), "/", ""), "\", ""), "?", ""), "*", ""), "[", ""), "]", "")
                        wsName = Left(ws.Range("C" & i).Value, 31)
                        .Name = wsName
            .Range("G6").Formula = "=""Date : ""&Data!D1"
 
Last edited:
Thanx it worked.

Now,I want to change the 1st line of below code to create the folder with name as selected mentioned on Above.i. e in below mentioned path D:\ & Folder to be created with above name


Code:
strFileName="D:\" & (<This line is to be edited to create a folder with name on as mentioned in post1 on selection)

Trim(ws.Range("C"&i).Value)&","&_

Trim(ws.Range("B"&i).Value)&".pdf"

.ExportAsFixedFormat Type:=xlTypePDF,_

Filename:=strFileName,_

OpenAfterPublish:=False
 
Last edited:
Back
Top