0

i want to loop through a column (item) then depend on value of cells create a folders with name of specific cell for example if find x = 20 then create folder "20_hhh" we have alot of 20 but i want just a folder if find 30 then create then create folder 30 _hhh and so on !

each time x (value of cell ) increase 10 time

this is an example of column

 Item

 10
 10
 10
 10
 20
 20
 30
 30
 40
 40
 40

i have a code , but it doesnt work, anybody can help me?

   Sub create_loop()

  Dim BrowseForFolder As String
  Dim fName5 As String
  Dim fName3 As String
  Dim fName1 As String
  Dim fName4 As String
  Dim x As String



 With Worksheets("Output_" & Date).Range("B1:B100")

  x = 20
 fName5 = .Range("D3").Value
 fName3 = "PO_"
 fName1 = "000"
 fName4 = "_"

 BrowseForFolder = "X:\fei"

 Set c = .Find(x, LookIn:=xlValues)
 If Not c Is Nothing Then
    firstAddress = c.Address
    Do
        MkDir  "my specific folder"

        x = 10 + x

        Set c = .FindNext(c)
    Loop While Not c Is Nothing And c.Address <> firstAddress
    End If
 End With

 End Sub   
  • **(a)** `FindNext` will not care about the fact that you increased `x` - it will happily find the next occurrence of value 20. **(b)** Your MkDir misses the name of the folder to be created. – FunThomas Feb 15 '19 at 14:31
  • 1
    I'd use a solution here to find the unique cell values, and then write a separate method that creates a folder (if one doesn't exist) for each unique value. https://stackoverflow.com/questions/36044556/quicker-way-to-get-all-unique-values-of-a-column-in-vba – Marc Feb 15 '19 at 14:41

0 Answers0