Christian Græsborg
asked on
Problems with making a index page from values in my msgbox.
Im new to VBA and got some problems with making a index page from values in my msgbox.
dont under stand why this 2 lines of codes dosent work.
dont under stand why this 2 lines of codes dosent work.
Set wsName = Me.BDClass.Value
and this oneshIndex.Range("B5").End(xlDown).Offset(1, 0).Select
Private Sub AddFromBtn_Click()
Dim r As Range
'Checks if BDClass allready exist
If BDClass.Value <> "" Then
Set r = wsIndex.Range("B:B").CurrentRegion.Find(BDClass.Value)
If Not r Is Nothing Then
MsgBox ("Der findes allerede en klassifikation med samme navn")
Exit Sub
End If
Else
MsgBox ("Der skal angives klassifikation")
Exit Sub
End If
'Checks if BDName allready exist
If BDName.Value <> "" Then
Set r = wsIndex.Range("C5").CurrentRegion.Find(BDName.Value)
If Not r Is Nothing Then
MsgBox ("Der findes allerede en bygningsdel med samme navn")
Exit Sub
End If
Else
MsgBox ("Der skal angives bygningsdel navn")
Exit Sub
End If
'Creates new sheet
Worksheets("Temp").Copy After:=Worksheets("Index") 'copy Temp to after Index
ActiveSheet.Name = BDClass.Value 'Renames the sheet to BDClass value
'Writes value to new sheet
ActiveSheet.Range("C3") = BDClass.Value
ActiveSheet.Range("E3") = BDName.Value
'Writes value to Index sheet
Dim shIndex As Worksheet
Set shIndex = ThisWorkbook.Sheets("Index")
Set wsName = Me.BDClass.Value '<-------------- Error----------------
shIndex.Range("B5").End(xlDown).Offset(1, 0).Select '<---------Error----------
ActiveCell.FormulaR1C1 = "='" & wsName & "'!R[-3]C[1]"
ActiveCell.Hyperlinks(1).SubAddress = "'" & wsName & "'!A1"
ActiveCell.Offset(0, 1).FormulaR1C1 = "='" & wsName & "'!R[-5]C[1]"
'Call wsSort '<----------Not tested-----------
Unload Me
End Sub
ASKER
Still getting an error at
I have included the excel file, if someone can help me with it
bygningsdel_journal-N03.xlsm
Set wsName = ThisWorkbook.Sheets(Me.BDClass.Value)
I have included the excel file, if someone can help me with it
bygningsdel_journal-N03.xlsm
This question needs an answer!
Become an EE member today
7 DAY FREE TRIALMembers can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
It's always better to avoid select/activate unless very much required.
Also, you should write Option Explicit on top of the Module so that you are bound to declare all the variables you use in the code.
See if the following tweaked lines work for you...
Open in new window