I can't deal with this code (split data based on selected column)

Alaa mg

Active Member
Joined
May 29, 2021
Messages
375
Office Version
  1. 2019
Hi experts
need helping to run this code . when put number the column into inputbox to filter and split data . it gives error mismatch in this line
VBA Code:
 rg2.Value = rg2.Value + 1
i no know what means theses lines
Code:
Set rg1 = sh1.Range("A8")
Set rg2 = sh1.Range("C4")
it seems the problem from them
this is the whole code
Code:
Sub parse_data()
  Dim sh1 As Worksheet, rg1 As Range, rg2 As Range
  Dim vcol As Variant, ky As Variant, i As Long
  Dim dic As Object, sName As String
 
  Application.ScreenUpdating = False
  vcol = Application.InputBox(prompt:="Which column would you like to filter by?", Title:="Filter column", Default:="10", Type:=1)
  If vcol = "" Or vcol = False Then Exit Sub
 
  Set dic = CreateObject("Scripting.Dictionary")
  Set sh1 = ActiveSheet
  Set rg1 = sh1.Range("A8")
  Set rg2 = sh1.Range("C4")
 
  If sh1.AutoFilterMode Then sh1.AutoFilterMode = False
  For i = rg1.Row + 1 To sh1.Cells(Rows.Count, vcol).End(3).Row
    dic(sh1.Cells(i, vcol).Value) = Empty
  Next
 
  For Each ky In dic.keys
    sh1.Range(rg1, sh1.Cells(Rows.Count, vcol).End(3)).AutoFilter vcol, ky
    rg2.Value = rg2.Value + 1
    sName = rg2.Value & " " & ky
    If Not Evaluate("=ISREF('" & sName & "'!A1)") Then
      Sheets.Add(After:=Sheets(Sheets.Count)).Name = sName
    Else
      Sheets(sName).Move After:=Worksheets(Worksheets.Count)
    End If
    sh1.Range("A1", sh1.Range("A" & Rows.Count).End(3)).EntireRow.Copy Sheets(sName).Range("A1")
  Next
 
  sh1.Activate
  sh1.AutoFilterMode = False
  Application.ScreenUpdating = True
End Sub
my data starts from A1: F
any help I'm so begginer
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Hi,
just a guess but try replacing this line

VBA Code:
 rg2.Value = rg2.Value + 1

with this

VBA Code:
rg2.Value = Val(rg2.Value) + 1

and see if resolves your issue

Dave
 
Upvote 0
Solution

Forum statistics

Threads
1,223,911
Messages
6,175,327
Members
452,635
Latest member
laura12345

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