I have a macro to copy and paste information from one sheet into another, looped to cycle through the different drop down options at the top of the page (i.e. you end up with one separate tab for each drop down option)
One part of the sheet contains text boxes linked to specific cell values, which copy across absolutely fine if I do this manually, but if I run the macro, all the text boxes show as 0 value, even though the formula is still set and the cells they are linked to still have a value in them. The only way to update the values in the text boxes seems to be to manually enter each text box twice! I have tried a few different 'refresh all objects' functions but none seem to do the trick. It is all very puzzling and I wondered if anyone had encountered a similar problem or can spot where I may have gone wrong please?
Here is the copy and paste macro:
Sub CopySheets()
'
Dim masterSheet As Worksheet
Dim hiddenSheet As Worksheet
Dim NewSheet As Worksheet
Dim myBook As Workbook
Dim lastRow As Long
Dim i As Long
Dim namesColumn
Dim Rng As String
On Error Resume Next
Application.ScreenUpdating = False
Set myBook = ActiveWorkbook
Set masterSheet = myBook.Worksheets("Mapping")
Set hiddenSheet = myBook.Worksheets("BSegment")
namesColumn = 6
lastRow = masterSheet.Cells(masterSheet.Rows.Count,namesColumn).End(xlUp).Row
For i = 1 To lastRow
With myBook
'New sheet
Set NewSheet =.Worksheets.Add(After:=.Worksheets("BSegment"))
End With
tabName =masterSheet.Cells(i, namesColumn)
NewSheet.Name =tabName
Rng =masterSheet.Cells(i, namesColumn)
hiddenSheet.Select
Range("A2").Value = Rng
Dim Ctrl As Object
For Each Ctrl InActiveSheet.OLEObjects
IfTypeName(Ctrl.Object) = "ComboBox" Then
Ctrl.Object.Text = Range("A2").Value
End If
Next
hiddenSheet.Select
Cells.Select
Selection.Copy
NewSheet.Select
ActiveSheet.Paste
Cells.Select
Application.CutCopyMode = False
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,SkipBlanks _
:=False,Transpose:=False
NewSheet.Cells(1,1).Value = tabName
Next i
End Sub
One part of the sheet contains text boxes linked to specific cell values, which copy across absolutely fine if I do this manually, but if I run the macro, all the text boxes show as 0 value, even though the formula is still set and the cells they are linked to still have a value in them. The only way to update the values in the text boxes seems to be to manually enter each text box twice! I have tried a few different 'refresh all objects' functions but none seem to do the trick. It is all very puzzling and I wondered if anyone had encountered a similar problem or can spot where I may have gone wrong please?
Here is the copy and paste macro:
Sub CopySheets()
'
Dim masterSheet As Worksheet
Dim hiddenSheet As Worksheet
Dim NewSheet As Worksheet
Dim myBook As Workbook
Dim lastRow As Long
Dim i As Long
Dim namesColumn
Dim Rng As String
On Error Resume Next
Application.ScreenUpdating = False
Set myBook = ActiveWorkbook
Set masterSheet = myBook.Worksheets("Mapping")
Set hiddenSheet = myBook.Worksheets("BSegment")
namesColumn = 6
lastRow = masterSheet.Cells(masterSheet.Rows.Count,namesColumn).End(xlUp).Row
For i = 1 To lastRow
With myBook
'New sheet
Set NewSheet =.Worksheets.Add(After:=.Worksheets("BSegment"))
End With
tabName =masterSheet.Cells(i, namesColumn)
NewSheet.Name =tabName
Rng =masterSheet.Cells(i, namesColumn)
hiddenSheet.Select
Range("A2").Value = Rng
Dim Ctrl As Object
For Each Ctrl InActiveSheet.OLEObjects
IfTypeName(Ctrl.Object) = "ComboBox" Then
Ctrl.Object.Text = Range("A2").Value
End If
Next
hiddenSheet.Select
Cells.Select
Selection.Copy
NewSheet.Select
ActiveSheet.Paste
Cells.Select
Application.CutCopyMode = False
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,SkipBlanks _
:=False,Transpose:=False
NewSheet.Cells(1,1).Value = tabName
Next i
End Sub