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
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