I have problem with an error number 91 - Object variable or with block variable not set which I don't understand.
When I search for it on the internet and here it says that you to set a value to the range or it will be set to nothing, but why can't I have it as nothing and then update it in my code?
What I'm trying to do is searching the headers in a For loop which goes through the sheets. I want it to search and find 3 specific headings.
Sub InfogaPrislista()
'
' InfogaPrislista Makro
' Adds a price list and updates the code in excel
'
Dim sKolumn As Range 'Fuse Column
Dim fKolumn As Range 'Fixed price kolumn
Dim rKolumn As Range 'Variable price kolumn
Dim Säkringar As ArrayList 'List with fuses
Dim Blad As ArrayList 'List with sheets
Set Säkringar = New ArrayList
Set Blad = New ArrayList
'Adding fuses to list
Säkringar.Add prislistor.Cells(4, 1)
Säkringar.Add prislistor.Cells(5, 1)
Säkringar.Add prislistor.Cells(6, 1)
Säkringar.Add prislistor.Cells(10, 1)
Säkringar.Add prislistor.Cells(11, 1)
Säkringar.Add prislistor.Cells(12, 1)
Säkringar.Add prislistor.Cells(13, 1)
Säkringar.Add prislistor.Cells(14, 1)
Säkringar.Add prislistor.Cells(15, 1)
Säkringar.Add prislistor.Cells(20, 1)
Säkringar.Add prislistor.Cells(21, 1)
Säkringar.Add prislistor.Cells(25, 1)
Säkringar.Add prislistor.Cells(26, 1)
'Adding sheets to list
Blad.Add brududden
Blad.Add rinnefors
Blad.Add järpforsen
Blad.Add rexed
Blad.Add sälboda
If prislistor.Range("B29") = "Enfas" Then
' Adds a specific fuse price list
'Sometimes I get an error here, but I think it depends on where and what I'm doing in the Excel workbook
prislistor.Range("A2:C7").Select
Selection.Copy
prislistor.Range("D2").Select
Selection.Insert Shift:=xlToRight
Application.CutCopyMode = False
prislistor.Range("E4:F7").Select
Selection.ClearContents
prislistor.Range("C29").Select
'This is supposed to search through the headings in every sheet in the sheets list for the different columns I set as ranges at row 6-8 in this code but I get error nr 91
Dim i as Long
For i = 0 To 4
sKolumn = Blad(i).Cells(1, 1).EntireRow.Find(What:="Säkring", LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:=False).Column
rKolumn = Blad(i).Cells(1, 1).EntireRow.Find(What:="Rörligtpris nät", LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:=False).Column
fKolumn = Blad(i).Cells(1, 1).EntireRow.Find(What:="Fastpris nät", LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:=False).Column
Next i
End if
End Sub
Sorry if this post becomes bad it's my first one with code. As I said earlier I have searched the internet and it is telling me to set a value to the ranges before I refer to them, which I don't understand why.