Create new sheet and save as per name in cell and value

earthworm

Active Member
Joined
May 19, 2009
Messages
368
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
Dear All,

I need a macro that will create a new workbook if the value of cell B2 >0 and then i will input some another macro to perform some condition's tweaking in another sheet and then and save it on desktop with the name present in cell A2 and so on . The macro will continue loop till B50 . This means if for each cell between B2:B50 if there is any value in each cell >0 then new run another macro and save it and move to next macro
Please assist.

I tired to play with below macro by making changes but its not working

VBA Code:
Sub df()
Dim i As Integer
Dim ii As Integer
Dim ws As Worksheet
Dim str As String
i = Application.WorksheetFunction.Count(Range("B:B"))

For i = 1 To Application.WorksheetFunction.Count(Range("B:B"))
ii = Sheets.Count
str = Range("B" & i).Value
If Range("B" & i).Value > 0 Then

ThisWorkbook.Sheets.Add(after:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count)).Name = str

End If
Sheets(1).Select
Next i
End Sub
 

Some videos you may like

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off

JLGWhiz

Well-known Member
Joined
Feb 7, 2012
Messages
12,526
Office Version
  1. 2013
Platform
  1. Windows
Maybe you can work with this

VBA Code:
Sub df()
Dim i As Long
Dim wb As Workbook
Dim str As String
With ActiveSheet
    For i = 1 To .Cells(Rows.Count, 2).End(xlUp).Row
        str = Range("B" & i).Value
            If Range("B" & i).Value > 0 Then
                ThisWorkbook.Sheets.Add(after:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count)).Name = str
                ActiveSheet.Copy 'create new workbook
                Set wb = ActiveWorkbook
                'Code to do stuff here
                wb.Close True 'saves and closes new workbook
            End If
    Next i
End With
End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,114,282
Messages
5,546,960
Members
410,765
Latest member
faris99
Top