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

earthworm

Well-known Member
Joined
May 19, 2009
Messages
759
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
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
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
 
Upvote 0

Forum statistics

Threads
1,214,914
Messages
6,122,211
Members
449,074
Latest member
cancansova

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