Get only text from Inputbox value

gssachin

Board Regular
Joined
Nov 14, 2013
Messages
155
Hi,

I want to enter the cell number and later same will get separated in character (i.e. BA5 it will get BA or if B5 then will get "B" ) But I m getting an error for the below codes due to "{"

Basically, I want the user will give a Cell reference based on that cell first and last row will get indentify.
my old code was "
"For Each locationCell In .Range("A2:A" & .Cells(.Rows.Count, "A").End(xlUp).Row)"

cellref = InputBox("Enter cell ref here")
newfilename = InputBox("Enter New File name")
For Each locationCell In .Range((cellref) & ":" & (Left(cellref, MIN(FIND({0,1,2,3,4,5,6,7,8,9},cellref &"0123456789"))-1)) & .Cells(.Rows.Count, (Left(cellref, MIN(FIND({0,1,2,3,4,5,6,7,8,9},cellref&"0123456789"))-1))).End(xlUp).Row)
 
Dear Sir,
I know if macro run twice it will not work due to same sheets available in the files, (user have to delete the existing sheets and then have to run macro)

But if we are keeping sheets in file then I dnt hv to use another macro where only sheets to keep in file, no individuals files require (that time I will delete extra generated files from folder)

Therefore I can use this macro for two different purposes in same time
 
Upvote 0

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Dear Sir,
I know if macro run twice it will not work due to same sheets available in the files, (user have to delete the existing sheets and then have to run macro)

But if we are keeping sheets in file then I dnt hv to use another macro where only sheets to keep in file, no individuals files require (that time I will delete extra generated files from folder)

Therefore I can use this macro for two different purposes in same time
Also I found that if my cell address is row is not 2 then and have empty row above then it giving error "method name of object _worksheet failed"

We have data where starting some rows are not to used while filtering data but when we creating worksheet or workbook that time we keeping this rows in new sheet/files (my old macro was working with this condition)
 
Upvote 0
Hi gssachin,

please have a look at the opening post in this thread and consider if the request has been solved. If so please mark this thread as solved.

Whenever I read

user have to delete the existing sheets and then have to run macro

to my opinion the concept used should be worked over. If I were a user of the workbook I would not want to be informed that I would need to delete sheets manually (this leads to the question which sheets should be deleted). Working around this could be to clear the contents of the sheets and use them again avoiding to delete manually.

Also I found that if my cell address is row is not 2 then and have empty row above then it giving error "method name of object _worksheet failed"

At what codeline? If it's when working with the collection code may be changed to

Rich (BB code):
   For Each rngCell In .Range(.Cells(rngStart.Row, rngStart.Column), .Cells(.Rows.Count, rngStart.Column).End(xlUp))
      objCollection.Add rngCell.Value, CStr(rngCell.Value)
    Next rngCell

Ciao,
Holger
 
Upvote 0
Hi gssachin,

maybe have a go with this altered code (change the number of sheets to keep from the left to suit):

VBA Code:
Public Sub Split_Sheet_By_Location_MrE1613908()
'https://www.mrexcel.com/board/threads/get-only-text-from-inputbox-value.1221260/#post-5972824
  Dim objCollection       As Collection
  Dim strPathNewFile      As String
  Dim strSaveFolder       As String
  Dim rngCell             As Range
  Dim rngStart            As Range
  Dim varKey              As Variant
  Dim varNewFile          As Variant
  Dim wsTargSheet         As Worksheet
  Dim lngAnswer           As Long
  Dim wb                  As Workbook
  Dim wsWork              As Worksheet
  
  Const cstrLastSheetName As String = "Last Sheet to keep"
  Const clngNumShKeep     As Long = 10

  Set wb = ThisWorkbook
  If wb.Worksheets.Count > clngNumShKeep Then
    lngAnswer = MsgBox("More than " & clngNumShKeep & " sheets in this workbook" & _
        vbCrLf & "Do you want to delete them?", vbYesNo, "Delete sheets?")
    Select Case lngAnswer
      Case vbYes
        lngAnswer = MsgBox("Do you want to delete them by hand?", vbYesNo, "How to delete?")
        Select Case lngAnswer
          Case vbYes
            MsgBox "Please delete sheets manually and start macro again.", vbInformation, "Ending here"
            GoTo end_here
          Case vbNo
            If Evaluate("ISREF('" & cstrLastSheetName & "'!A1)") Then
              lngAnswer = MsgBox("Do you want to delete all sheets to the right of '" & _
                  cstrLastSheetName & "'?", vbYesNo, "Which sheets?")
              Select Case lngAnswer
                Case vbYes
                  Application.DisplayAlerts = False
                  Do While wb.Worksheets(wb.Worksheets.Count).Name <> cstrLastSheetName
                    wb.Worksheets(wb.Worksheets.Count).Delete
                  Loop
                  Application.DisplayAlerts = True
                Case vbNo
                  lngAnswer = MsgBox("Keep all sheets and proceed?", vbYesNo, "Continue?")
                  Select Case lngAnswer
                    Case vbYes
                      'continue
                    Case vbNo
                      MsgBox "Ending macro here.", vbExclamation, "Stop procedure"
                      GoTo end_here
                  End Select
              End Select
            Else
              lngAnswer = MsgBox("Do you want to delete all sheets from the right which exceed the index of '" & _
                  clngNumShKeep & "'?", vbYesNo, "Which sheets?")
              Select Case lngAnswer
                Case vbYes
                  Application.DisplayAlerts = False
                  Do While wb.Worksheets.Count > clngNumShKeep
                    wb.Worksheets(wb.Worksheets.Count).Delete
                  Loop
                  Application.DisplayAlerts = True
                Case vbNo
                  lngAnswer = MsgBox("Keep all sheets and proceed?", vbYesNo, "Continue?")
                  Select Case lngAnswer
                    Case vbYes
                      'continue
                    Case vbNo
                      MsgBox "Ending macro here.", vbExclamation, "Stop procedure"
                      GoTo end_here
                  End Select
              End Select
            End If
        End Select
      Case vbNo
    End Select
  End If

  lngAnswer = MsgBox("Do you want to export the created sheets to individual workbooks?", vbYesNo, "Export data?")

  Application.ScreenUpdating = False
  If lngAnswer = vbYes Then
    With Application.FileDialog(msoFileDialogFolderPicker)
      .AllowMultiSelect = False
      .Title = "Choose a folder"
      If .Show = -1 Then
        strSaveFolder = .SelectedItems(1)
        If Right(Trim(strSaveFolder), 1) <> "\" Then strSaveFolder = Trim(strSaveFolder) & "\"
      Else
        MsgBox "No folder selected", vbInformation, "Ending..."
        GoTo end_here
      End If
    End With
  End If
  
retry:
  varNewFile = Application.InputBox("Enter Sheet Name", "Sheet Nmae", Type:=2)
  If varNewFile = False Then
    MsgBox "No sheet name entered", vbInformation, "Exit procedure"
    GoTo end_here
  Else
    If Not Evaluate("ISREF('" & varNewFile & "'!A1)") Then
      If MsgBox("Can't find sheet '" & varNewFile & "'." & vbCrLf & "Try Again or Cancel?", vbOKCancel, "Typo?..") = vbYes Then
        GoTo retry
      Else
        GoTo end_here
      End If
    End If
  End If
  Set wsWork = wb.Worksheets(varNewFile)
  
  With wsWork
    If .AutoFilterMode Then .AutoFilterMode = False
    Set objCollection = New Collection
    On Error Resume Next
    Set rngStart = Application.InputBox("Choose the starting cell in the sheet or enter address like 'A2'", "Start Cell", Type:=8)
    If Err.Number <> 0 Then
      MsgBox "No proper selection to start with", vbInformation, "Exit procedure"
      GoTo end_here
    End If
    If lngAnswer = vbYes Then
      varNewFile = Application.InputBox("Enter New File name", "New File", Type:=2)
      If varNewFile = False Then
        MsgBox "No new file name entered", vbInformation, "Exit procedure"
        GoTo end_here
      End If
    End If
    
    For Each rngCell In .Range(rngStart, .Cells(.Rows.Count, rngStart.Column).End(xlUp))
      objCollection.Add rngCell.Value, CStr(rngCell.Value)
    Next rngCell
    Err.Clear
    On Error GoTo 0
    
    'Autofilter column A by each location and copy results to location sheet
    For Each varKey In objCollection
      If Not Evaluate("ISREF('" & CStr(varKey) & "'!A1)") Then
        Set wsTargSheet = Worksheets.Add(after:=wb.Worksheets(wb.Worksheets.Count))
        wsTargSheet.Name = CStr(varKey)
      Else
        Set wsTargSheet = wb.Worksheets(CStr(varKey))
        wsTargSheet.UsedRange.ClearContents
      End If
      If .AutoFilterMode Then .AutoFilterMode = False
      .UsedRange.AutoFilter Field:=rngStart.Column, Operator:=xlFilterValues, Criteria1:="=" & varKey 'Field:=1 means column A
      .UsedRange.Copy wsTargSheet.Range("A1")
      wsTargSheet.UsedRange.EntireColumn.AutoFit
      
      If lngAnswer = vbYes Then
        strPathNewFile = strSaveFolder & varNewFile & "_" & varKey & ".xlsx"
        If Dir(strPathNewFile) <> "" Then Kill strPathNewFile
        wsTargSheet.Copy
        ActiveWorkbook.SaveAs strPathNewFile, FileFormat:=51
        ActiveWorkbook.Close SaveChanges:=False
      End If
    Next varKey
  
    'Remove autofilter
    .UsedRange.AutoFilter
    .Activate
  End With
  
  Application.ScreenUpdating = True
  
  MsgBox "Done"

end_here:
  Err.Clear
  Set wsTargSheet = Nothing
  Set rngStart = Nothing
  Set wsWork = Nothing
  Set wb = Nothing
End Sub

Ciao,
Holger
 
Upvote 0
Dear Sir,

This is beyond my expectations 😍😍😍🙏🙏🙏

Only one last thing want to share this macro copy data from row "1" and then filter cell value i. e row no 8 (if cell value given as "Ab8"

In between rows (2 to 7 row number) not get copied to New sheet as well as new workbook

Is it possible to copied full data from A1 to last row (after filtering) to new sheet/ workbook.... Even my filter start from ab8
 
Upvote 0
Hi gssachin,

if you mark the thread as solved thereafter :cool:


It's this codeline that should be altered:

VBA Code:
      .UsedRange.AutoFilter Field:=rngStart.Column, Operator:=xlFilterValues, Criteria1:="=" & varKey 'Field:=1 means column A

which would start with the first row of data on the sheet (for most users this means A1) to read

VBA Code:
      .UsedRange.Rows(rngStart.Row - 1).AutoFilter Field:=rngStart.Column, Operator:=xlFilterValues, Criteria1:="=" & varKey 'Field:=1 means column A


where the row above the starting cell will be used to set the filter.

Whole code might look like this:

VBA Code:
Public Sub Split_Sheet_By_Location_MrE1613908_Mod()
'https://www.mrexcel.com/board/threads/get-only-text-from-inputbox-value.1221260
'2022-11-11, request to start Filtering leaving some rows above that row.
'Data starts in A1, so
  Dim objCollection       As Collection
  Dim strPathNewFile      As String
  Dim strSaveFolder       As String
  Dim rngCell             As Range
  Dim rngStart            As Range
  Dim varKey              As Variant
  Dim varNewFile          As Variant
  Dim wsTargSheet         As Worksheet
  Dim lngAnswer           As Long
  Dim wb                  As Workbook
  Dim wsWork              As Worksheet
  
  Const cstrLastSheetName As String = "Last Sheet to keep"
  Const clngNumShKeep     As Long = 3

  Set wb = ThisWorkbook
  If wb.Worksheets.Count > clngNumShKeep Then
    lngAnswer = MsgBox("More than " & clngNumShKeep & " sheets in this workbook" & _
        vbCrLf & "Do you want to delete them?", vbYesNo, "Delete sheets?")
    Select Case lngAnswer
      Case vbYes
        lngAnswer = MsgBox("Do you want to delete them by hand?", vbYesNo, "How to delete?")
        Select Case lngAnswer
          Case vbYes
            MsgBox "Please delete sheets manually and start macro again.", vbInformation, "Ending here"
            GoTo end_here
          Case vbNo
            If Evaluate("ISREF('" & cstrLastSheetName & "'!A1)") Then
              lngAnswer = MsgBox("Do you want to delete all sheets to the right of '" & _
                  cstrLastSheetName & "'?", vbYesNo, "Which sheets?")
              Select Case lngAnswer
                Case vbYes
                  Application.DisplayAlerts = False
                  Do While wb.Worksheets(wb.Worksheets.Count).Name <> cstrLastSheetName
                    wb.Worksheets(wb.Worksheets.Count).Delete
                  Loop
                  Application.DisplayAlerts = True
                Case vbNo
                  lngAnswer = MsgBox("Keep all sheets and proceed?", vbYesNo, "Continue?")
                  Select Case lngAnswer
                    Case vbYes
                      'continue
                    Case vbNo
                      MsgBox "Ending macro here.", vbExclamation, "Stop procedure"
                      GoTo end_here
                  End Select
              End Select
            Else
              lngAnswer = MsgBox("Do you want to delete all sheets from the right which exceed the index of '" & _
                  clngNumShKeep & "'?", vbYesNo, "Which sheets?")
              Select Case lngAnswer
                Case vbYes
                  Application.DisplayAlerts = False
                  Do While wb.Worksheets.Count > clngNumShKeep
                    wb.Worksheets(wb.Worksheets.Count).Delete
                  Loop
                  Application.DisplayAlerts = True
                Case vbNo
                  lngAnswer = MsgBox("Keep all sheets and proceed?", vbYesNo, "Continue?")
                  Select Case lngAnswer
                    Case vbYes
                      'continue
                    Case vbNo
                      MsgBox "Ending macro here.", vbExclamation, "Stop procedure"
                      GoTo end_here
                  End Select
              End Select
            End If
        End Select
      Case vbNo
    End Select
  End If

  lngAnswer = MsgBox("Do you want to export the created sheets to individual workbooks?", vbYesNo, "Export data?")

  Application.ScreenUpdating = False
  If lngAnswer = vbYes Then
    With Application.FileDialog(msoFileDialogFolderPicker)
      .AllowMultiSelect = False
      .Title = "Choose a folder"
      If .Show = -1 Then
        strSaveFolder = .SelectedItems(1)
        If Right(Trim(strSaveFolder), 1) <> "\" Then strSaveFolder = Trim(strSaveFolder) & "\"
      Else
        MsgBox "No folder selected", vbInformation, "Ending..."
        GoTo end_here
      End If
    End With
  End If
  
retry:
  varNewFile = Application.InputBox("Enter Sheet Name", "Sheet Name", Type:=2)
  If varNewFile = False Then
    MsgBox "No sheet name entered", vbInformation, "Exit procedure"
    GoTo end_here
  Else
    If Not Evaluate("ISREF('" & varNewFile & "'!A1)") Then
      If MsgBox("Can't find sheet '" & varNewFile & "'." & vbCrLf & "Try Again or Cancel?", vbOKCancel, "Typo?..") = vbYes Then
        GoTo retry
      Else
        GoTo end_here
      End If
    End If
  End If
  Set wsWork = wb.Worksheets(varNewFile)
  
  With wsWork
    If .AutoFilterMode Then .AutoFilterMode = False
    Set objCollection = New Collection
    On Error Resume Next
    Set rngStart = Application.InputBox("Choose the starting cell in the sheet or enter address like 'A2'", "Start Cell", Type:=8)
    If Err.Number <> 0 Then
      MsgBox "No proper selection to start with", vbInformation, "Exit procedure"
      GoTo end_here
    End If
    If lngAnswer = vbYes Then
      varNewFile = Application.InputBox("Enter New File name", "New File", Type:=2)
      If varNewFile = False Then
        MsgBox "No new file name entered", vbInformation, "Exit procedure"
        GoTo end_here
      End If
    End If
    
    For Each rngCell In .UsedRange.Range(rngStart, .Cells(.Rows.Count, rngStart.Column).End(xlUp))
      objCollection.Add rngCell.Value, CStr(rngCell.Value)
    Next rngCell
    Err.Clear
    On Error GoTo 0
    
    'Autofilter column A by each location and copy results to location sheet
    For Each varKey In objCollection
      If Not Evaluate("ISREF('" & CStr(varKey) & "'!A1)") Then
        Set wsTargSheet = Worksheets.Add(after:=wb.Worksheets(wb.Worksheets.Count))
        wsTargSheet.Name = CStr(varKey)
      Else
        Set wsTargSheet = wb.Worksheets(CStr(varKey))
        wsTargSheet.UsedRange.ClearContents
      End If
      If .AutoFilterMode Then .AutoFilterMode = False
      .UsedRange.Rows(rngStart.Row - 1).AutoFilter Field:=rngStart.Column, Operator:=xlFilterValues, Criteria1:="=" & varKey 'Field:=1 means column A
      .UsedRange.Copy wsTargSheet.Range("A1")
      wsTargSheet.UsedRange.EntireColumn.AutoFit
      
      If lngAnswer = vbYes Then
        strPathNewFile = strSaveFolder & varNewFile & "_" & varKey & ".xlsx"
        If Dir(strPathNewFile) <> "" Then Kill strPathNewFile
        wsTargSheet.Copy
        ActiveWorkbook.SaveAs strPathNewFile, FileFormat:=51
        ActiveWorkbook.Close SaveChanges:=False
      End If
    Next varKey
  
    'Remove autofilter
    .UsedRange.AutoFilter
    .Activate
  End With
  
  Application.ScreenUpdating = True
  
  MsgBox "Done"

end_here:
  Err.Clear
  Set wsTargSheet = Nothing
  Set rngStart = Nothing
  Set wsWork = Nothing
  Set wb = Nothing
End Sub

Ciao,
Holger
 
Upvote 0
Solution
Hi gssachin,

if you mark the thread as solved thereafter :cool:


It's this codeline that should be altered:

VBA Code:
      .UsedRange.AutoFilter Field:=rngStart.Column, Operator:=xlFilterValues, Criteria1:="=" & varKey 'Field:=1 means column A

which would start with the first row of data on the sheet (for most users this means A1) to read

VBA Code:
      .UsedRange.Rows(rngStart.Row - 1).AutoFilter Field:=rngStart.Column, Operator:=xlFilterValues, Criteria1:="=" & varKey 'Field:=1 means column A


where the row above the starting cell will be used to set the filter.

Whole code might look like this:

VBA Code:
Public Sub Split_Sheet_By_Location_MrE1613908_Mod()
'https://www.mrexcel.com/board/threads/get-only-text-from-inputbox-value.1221260
'2022-11-11, request to start Filtering leaving some rows above that row.
'Data starts in A1, so
  Dim objCollection       As Collection
  Dim strPathNewFile      As String
  Dim strSaveFolder       As String
  Dim rngCell             As Range
  Dim rngStart            As Range
  Dim varKey              As Variant
  Dim varNewFile          As Variant
  Dim wsTargSheet         As Worksheet
  Dim lngAnswer           As Long
  Dim wb                  As Workbook
  Dim wsWork              As Worksheet
 
  Const cstrLastSheetName As String = "Last Sheet to keep"
  Const clngNumShKeep     As Long = 3

  Set wb = ThisWorkbook
  If wb.Worksheets.Count > clngNumShKeep Then
    lngAnswer = MsgBox("More than " & clngNumShKeep & " sheets in this workbook" & _
        vbCrLf & "Do you want to delete them?", vbYesNo, "Delete sheets?")
    Select Case lngAnswer
      Case vbYes
        lngAnswer = MsgBox("Do you want to delete them by hand?", vbYesNo, "How to delete?")
        Select Case lngAnswer
          Case vbYes
            MsgBox "Please delete sheets manually and start macro again.", vbInformation, "Ending here"
            GoTo end_here
          Case vbNo
            If Evaluate("ISREF('" & cstrLastSheetName & "'!A1)") Then
              lngAnswer = MsgBox("Do you want to delete all sheets to the right of '" & _
                  cstrLastSheetName & "'?", vbYesNo, "Which sheets?")
              Select Case lngAnswer
                Case vbYes
                  Application.DisplayAlerts = False
                  Do While wb.Worksheets(wb.Worksheets.Count).Name <> cstrLastSheetName
                    wb.Worksheets(wb.Worksheets.Count).Delete
                  Loop
                  Application.DisplayAlerts = True
                Case vbNo
                  lngAnswer = MsgBox("Keep all sheets and proceed?", vbYesNo, "Continue?")
                  Select Case lngAnswer
                    Case vbYes
                      'continue
                    Case vbNo
                      MsgBox "Ending macro here.", vbExclamation, "Stop procedure"
                      GoTo end_here
                  End Select
              End Select
            Else
              lngAnswer = MsgBox("Do you want to delete all sheets from the right which exceed the index of '" & _
                  clngNumShKeep & "'?", vbYesNo, "Which sheets?")
              Select Case lngAnswer
                Case vbYes
                  Application.DisplayAlerts = False
                  Do While wb.Worksheets.Count > clngNumShKeep
                    wb.Worksheets(wb.Worksheets.Count).Delete
                  Loop
                  Application.DisplayAlerts = True
                Case vbNo
                  lngAnswer = MsgBox("Keep all sheets and proceed?", vbYesNo, "Continue?")
                  Select Case lngAnswer
                    Case vbYes
                      'continue
                    Case vbNo
                      MsgBox "Ending macro here.", vbExclamation, "Stop procedure"
                      GoTo end_here
                  End Select
              End Select
            End If
        End Select
      Case vbNo
    End Select
  End If

  lngAnswer = MsgBox("Do you want to export the created sheets to individual workbooks?", vbYesNo, "Export data?")

  Application.ScreenUpdating = False
  If lngAnswer = vbYes Then
    With Application.FileDialog(msoFileDialogFolderPicker)
      .AllowMultiSelect = False
      .Title = "Choose a folder"
      If .Show = -1 Then
        strSaveFolder = .SelectedItems(1)
        If Right(Trim(strSaveFolder), 1) <> "\" Then strSaveFolder = Trim(strSaveFolder) & "\"
      Else
        MsgBox "No folder selected", vbInformation, "Ending..."
        GoTo end_here
      End If
    End With
  End If
 
retry:
  varNewFile = Application.InputBox("Enter Sheet Name", "Sheet Name", Type:=2)
  If varNewFile = False Then
    MsgBox "No sheet name entered", vbInformation, "Exit procedure"
    GoTo end_here
  Else
    If Not Evaluate("ISREF('" & varNewFile & "'!A1)") Then
      If MsgBox("Can't find sheet '" & varNewFile & "'." & vbCrLf & "Try Again or Cancel?", vbOKCancel, "Typo?..") = vbYes Then
        GoTo retry
      Else
        GoTo end_here
      End If
    End If
  End If
  Set wsWork = wb.Worksheets(varNewFile)
 
  With wsWork
    If .AutoFilterMode Then .AutoFilterMode = False
    Set objCollection = New Collection
    On Error Resume Next
    Set rngStart = Application.InputBox("Choose the starting cell in the sheet or enter address like 'A2'", "Start Cell", Type:=8)
    If Err.Number <> 0 Then
      MsgBox "No proper selection to start with", vbInformation, "Exit procedure"
      GoTo end_here
    End If
    If lngAnswer = vbYes Then
      varNewFile = Application.InputBox("Enter New File name", "New File", Type:=2)
      If varNewFile = False Then
        MsgBox "No new file name entered", vbInformation, "Exit procedure"
        GoTo end_here
      End If
    End If
   
    For Each rngCell In .UsedRange.Range(rngStart, .Cells(.Rows.Count, rngStart.Column).End(xlUp))
      objCollection.Add rngCell.Value, CStr(rngCell.Value)
    Next rngCell
    Err.Clear
    On Error GoTo 0
   
    'Autofilter column A by each location and copy results to location sheet
    For Each varKey In objCollection
      If Not Evaluate("ISREF('" & CStr(varKey) & "'!A1)") Then
        Set wsTargSheet = Worksheets.Add(after:=wb.Worksheets(wb.Worksheets.Count))
        wsTargSheet.Name = CStr(varKey)
      Else
        Set wsTargSheet = wb.Worksheets(CStr(varKey))
        wsTargSheet.UsedRange.ClearContents
      End If
      If .AutoFilterMode Then .AutoFilterMode = False
      .UsedRange.Rows(rngStart.Row - 1).AutoFilter Field:=rngStart.Column, Operator:=xlFilterValues, Criteria1:="=" & varKey 'Field:=1 means column A
      .UsedRange.Copy wsTargSheet.Range("A1")
      wsTargSheet.UsedRange.EntireColumn.AutoFit
     
      If lngAnswer = vbYes Then
        strPathNewFile = strSaveFolder & varNewFile & "_" & varKey & ".xlsx"
        If Dir(strPathNewFile) <> "" Then Kill strPathNewFile
        wsTargSheet.Copy
        ActiveWorkbook.SaveAs strPathNewFile, FileFormat:=51
        ActiveWorkbook.Close SaveChanges:=False
      End If
    Next varKey
 
    'Remove autofilter
    .UsedRange.AutoFilter
    .Activate
  End With
 
  Application.ScreenUpdating = True
 
  MsgBox "Done"

end_here:
  Err.Clear
  Set wsTargSheet = Nothing
  Set rngStart = Nothing
  Set wsWork = Nothing
  Set wb = Nothing
End Sub

Ciao,
Holger
Dear Sir,

It work's 😊🙏💐🎉🎊, Finally I closed this thread 😉
 
Upvote 0
Hi gssachin,

glad that I could put some code together to help you. Thanks for the feedback.

Ciao,
Holger
 
Upvote 0
It work's 😊🙏💐🎉🎊, Finally I closed this thread 😉
The marked solution post has been switched accordingly.

@gssachin: Questions are not closed in the MrExcel Message Board, however, we mark the post as the solution that answered the question to help future readers. So, in your next questions, that would be great if you could mark the post that answered the question instead of your feedback post. No action is required for this thread.
 
Upvote 0

Forum statistics

Threads
1,222,115
Messages
6,164,012
Members
451,867
Latest member
csktwyr

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top