help me with macro

santoshloka

Board Regular
Joined
Aug 31, 2017
Messages
125
i need help with macro ..little urgent

my inention to copy the data from one sheet to another data as well as to create sheet with taking reference of cell value
i have 2 sheets
Abstract
MB-BOQ

Code:
Sub CreateSheetsFromAList()
    Application.ScreenUpdating = False
    Dim MyCell As Range
    Dim MyRange As Range
    Dim MySheetName As String
    Dim MyFormulas As Variant
    Dim wks a worksheet
    
    Set MyRange = Sheets("MB-BOQ").Range("C2:F2")
    


                    Sheets("INPUT").Copy after:=Sheets(Sheets.Count)
                    Sheets(Sheets.Count).Name = .Cells(MyRange, 1).Value
                Else
                    Set wks = Nothing
                    MsgBox "Sheets: " & .Cells(MyRange, 1).Value & vbCrLf & vbCrLf & "Already exists!", vbExclamation, "Sheet Exists"
                End If
            End If


   
   If Not wks Is Nothing Then Set wks = Nothing


    For Each MyCell In MyRange
    
        MySheetName = Replace(Replace(MyCell.Value, "*", "x"), "?", "S")
        MyFormulas = Array("='" & MySheetName & "'!$I$65", "", "='" & MySheetName & "'!$I$80", "='" & MySheetName & "'!$I$88", "='" & MySheetName & "'!$I$94", "='" & MySheetName & "'!$I$99", "", "='" & MySheetName & "'!$I$111", "='" & MySheetName & "'!$I$117", "='" & MySheetName & "'!$I$121", "", "='" & MySheetName & "'!$I$127", "='" & MySheetName & "'!$I$132", "='" & MySheetName & "'!$I$134", "='" & MySheetName & "'!$I$135", "='" & MySheetName & "'!$I$138", "='" & MySheetName & "'!$I$141", "='" & MySheetName & "'!$I$144", "", "='" & MySheetName & "'!$I$149", "='" & MySheetName & "'!$I$150", "='" & MySheetName & "'!$I$151", "='" & MySheetName & "'!$I$152", "='" & MySheetName & "'!$I$155", "='" & MySheetName & "'!$I$158", "='" & MySheetName & "'!$I$164", "='" & MySheetName & "'!$I$167", "='" & MySheetName & "'!$I$170", "='" & MySheetName & "'!$I$173", "='" & MySheetName & "'!$I$124", "='" & MySheetName & "'!$I$125", "=1")
        
        If SheetExists(MySheetName) Then
        
        'Sheet already exists: No need to create a new one
        MsgBox "Sheet " & MySheetName & " already exists!", vbOKOnly, "Oops!"
        Else
            Sheets.Add after:=Sheets(Sheets.Count) 'creates a new worksheet
            Sheets(Sheets.Count).Name = MySheetName ' renames the new worksheet
        End If
        
        MyCell.Offset(3, 0).Resize(32, 1).Formula = Application.Transpose(MyFormulas)   'Enter formulas
        
    Next MyCell
        Application.ScreenUpdating = True
End Sub




 Function SheetExists(shtName As String, Optional wb As Workbook) As Boolean
    Dim sht As Worksheet




     If wb Is Nothing Then Set wb = ThisWorkbook
     On Error Resume Next
     Set sht = wb.Sheets(shtName)
     On Error GoTo 0
     SheetExists = Not sht Is Nothing
 End Function
 
i want this to tigger by event procedure?
where should i paste the code?
Code:
Sub TabSheets_Click()
Dim i As Long
ListBox1.Clear
    For i = 1 To Sheets.Count
        ListBox1.AddItem Sheets(i).Name
    Next
End Sub
Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
Sheets(ListBox1.Value).Activate
End Sub

iam getting error macro is not avalable or may be disabled
 
Last edited:
Upvote 0

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.

Forum statistics

Threads
1,224,828
Messages
6,181,210
Members
453,023
Latest member
alabaz

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