Refresh formula in all the sheets after running macro

mohammadimran

New Member
Joined
May 30, 2018
Messages
10
Good Day everyone,

I am trying to copy Vendor names along with their relevant details into a new sheet. There are approx over 50 unique vendors in my sheet. My VBA macro works just and it takes all the vendors data into new worksheets with one addition that I also insert a row in every sheet and enter a formula in cell B1 and cell A1 in every new sheet.

The Issue I am facing is that after the macro is finished and I get all the sheets done. the data in cell B1 and A1 is not refreshed and instead its the same data in every sheet and I have to manually go to every sheet to update the cell values in B1 in order to update A1.

I have tried different combinations but failed so far. Any help is much appreciated.

My code is as follows;


Function GetWorksheet(shtName As String) As Worksheet
On Error Resume Next
Set GetWorksheet = Worksheets(shtName)
End Function




Sub Copy_Data_to_New_Tabs()


Dim x As Range
Dim rng As Range
On Error GoTo Errorcatch
Dim last As Long
Dim sht As String




'specify sheet name in which the data is stored
sht = "Detail"


'change filter column in the following code
last = Sheets(sht).Cells(Rows.Count, "A").End(xlUp).Row
Set rng = Sheets(sht).Range("A1:J" & last)


Sheets(sht).Range("A1:A" & last).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Range("BB1"), Unique:=True


For Each x In Range([BB2], Cells(Rows.Count, "BB").End(xlUp))
With rng
.AutoFilter
.AutoFilter Field:=1, Criteria1:=x.Value
.SpecialCells(xlCellTypeVisible).Copy


Sheets.Add(After:=Sheets(Sheets.Count)).Name = x.Value
ActiveSheet.Paste

'Adds a Row in every new sheet after pasting data and puts formula in Cell B1 and Cell A1



Rows("1:1").Select
Selection.Insert Shift:=xlDown
Range("B1").Formula = "=(REPLACE(CELL(""filename""),1,FIND(""]"",CELL(""filename"")),""""))"
Range("A1").Formula = "=VLOOKUP(B1,'C:\Users\mimran\Documents\Working - RMA\[Vendor Emails.xlsx]Sheet1'!$A:$B,2,0)"




End With
Next x


' Turn off filter
Sheets(sht).AutoFilterMode = False


With Application
.CutCopyMode = False
.ScreenUpdating = True




Exit Sub


Errorcatch:
MsgBox Err.Description


End With


End Sub
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Add

Code:
Calculate

at the end of your code.
 
Upvote 0

Forum statistics

Threads
1,214,810
Messages
6,121,690
Members
449,048
Latest member
81jamesacct

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