I am trying to select data between rows that the user inputs her/himself (As letters), I am also trying to limit the data so that it compares the values in one row and copies only the data with the same value in the chosen "compare column". Then it selects all the data with the same value in the "compare column" and saves it to a new sheet.
That is how it is supposed to work, however. I have been stuck for hours with the Range selection. I have saved the user input as strings, i.e if I want the data between ranges A3 to D19 it is saved as "A3" and "D19". When I then put it into a range:
Set selValue = arbEx.range(rangeStart & ":" & rangeStopp)
selValue.Copy
I get the "Application-defined or object-defined error". I have tried with countless different inputs for range, but I always get the same error. The code works if I comment the two above lines so the problems should be there.
Below is the full code,
Sub Lösning()
Set newWb = Workbooks.Add
'Set ActiveSheet = ActiveWorkbook.ActiveSheet
'Förhindrar screenflicker
Application.ScreenUpdating = False
'Skapar två sheets som används i programmet
Dim param As Worksheet
Set param = ThisWorkbook.Sheets("Parametrar")
Dim arbEx As Worksheet
Set arbEx = ThisWorkbook.Sheets("Arbets ex")
'Kod för att hämta startvädet av kolumn
Dim start As String
start = param.Cells(4, 3).Value
'Kod för att hämta slutvärdet av kolumn
Dim stopp As String
stopp = param.Cells(4, 4).Value
'Deklaration av variabler
Dim counter1 As Long
Dim counter2 As Long
Dim counter3 As Long
Dim rangeStart As String
Dim rangeStopp As String
Dim rangeFinal As String
'dela upp efter kolumn
Dim koluParam As String
Dim paramCheck As String
'Kolumn att dela upp efter
koluParam = param.Cells(4, 2).Value
'Algoritm för kopiering av valda kolumner
For i = 3 To 10000
paramCheck = arbEx.Cells(i, koluParam).Value
counter1 = counter1 + 1
counter2 = counter2 + 1
counter3 = counter3 + 1
If (paramCheck <> arbEx.Cells((i + 1), koluParam).Value) Then
counter3 = counter2 - counter1
rangeStart = start & counter3
rangeStopp = stopp & counter2
'-------problem here
Set selValue = arbEx.range(rangeStart & ":" & rangeStopp)
selValue.Copy
'-----------------
newWb.Activate
Sheets.Add
ActiveSheet.Paste
counter1 = 0
End If
Next
'Rensar clipboard
Application.CutCopyMode = False
'Aktiverar uppdatering för att visa all data
Application.ScreenUpdating = True
End Sub