Monica_hey
New Member
- Joined
- Jun 6, 2022
- Messages
- 1
- Office Version
- 2016
- Platform
- Windows
Hi guys,
I am new to VBA. Working on a simple data input userform. Need some help with on function. Appreciate your input!!
My goal is to:
(1) Create my column A with the data input from user (this is done and working ok, only that I need to number it if the same date already exists);
(2) Create a folder with the value of the created column A.
Code is as below. Problem is that I need a suffix at the end of column A if the same date already exists. And folder is outside of the current folder, need it to be at the same folder.
Thank you for your help!
________________________
ws1.Range("A" & i) = pj_nm_bx.Value & "-" & pr_nm_bx.Value & "-" & arr & "-0"
pth = Application.ThisWorkbook.Path
Set FileSystem = CreateObject("Scripting.FileSystemObject")
For n = 1 To 100
If 0 < Application.WorksheetFunction.CountIf(Sheets("TicketList").Range("A:A"), ws1.Range("A" & i)) < n Then
ws1.Range("A" & i) = ws1.Range("A" & i) & n
Else
ws1.Range("A" & i) = ws1.Range("A" & i) & (n + 1)
End If
newFolder = ws1.Range("A" & i)
If Dir(pth & newFolder, vbDirectory) = "" Then
MkDir pth & newFolder
End If
Exit For
Next
Range("A" & i) = Range("A" & i) & t
'folderNm = Range("A" & i)
newFolder = Range("A" & i)
FileSystem.CreateFolder (newFolder)
I am new to VBA. Working on a simple data input userform. Need some help with on function. Appreciate your input!!
My goal is to:
(1) Create my column A with the data input from user (this is done and working ok, only that I need to number it if the same date already exists);
(2) Create a folder with the value of the created column A.
Code is as below. Problem is that I need a suffix at the end of column A if the same date already exists. And folder is outside of the current folder, need it to be at the same folder.
Thank you for your help!
________________________
ws1.Range("A" & i) = pj_nm_bx.Value & "-" & pr_nm_bx.Value & "-" & arr & "-0"
pth = Application.ThisWorkbook.Path
Set FileSystem = CreateObject("Scripting.FileSystemObject")
For n = 1 To 100
If 0 < Application.WorksheetFunction.CountIf(Sheets("TicketList").Range("A:A"), ws1.Range("A" & i)) < n Then
ws1.Range("A" & i) = ws1.Range("A" & i) & n
Else
ws1.Range("A" & i) = ws1.Range("A" & i) & (n + 1)
End If
newFolder = ws1.Range("A" & i)
If Dir(pth & newFolder, vbDirectory) = "" Then
MkDir pth & newFolder
End If
Exit For
Next
Range("A" & i) = Range("A" & i) & t
'folderNm = Range("A" & i)
newFolder = Range("A" & i)
FileSystem.CreateFolder (newFolder)