I have been happily running macros in varous workbooks. These macros are stored in personal.xlsb.
Today I added a new sub & now my macros are performing the macros in the personal.xlsb file.eg with the following VBA, the selection of the blue cells happens in the correct file but the new worksheet is added in the personal.xlsb file.
This is also happening with all of my other macros stored in xlsb. Help please I have an urgent deadline!
Today I added a new sub & now my macros are performing the macros in the personal.xlsb file.eg with the following VBA, the selection of the blue cells happens in the correct file but the new worksheet is added in the personal.xlsb file.
VBA Code:
Sub CopyBlueColumnsToNewWorksheet()
Dim ws As Worksheet
Dim newWs As Worksheet
Dim lastColumn As Long
Dim i As Long
Dim j As Long
Dim blueColumns() As Boolean
Dim blueCount As Long
Dim wb As Workbook
' Set a reference to the active worksheet
Set ws = ActiveSheet
' Find the last column in row 1
lastColumn = ws.Cells(1, ws.Columns.Count).End(xlToLeft).Column
' Initialize an array to track blue columns
ReDim blueColumns(1 To lastColumn)
' Check each cell in row 1 for blue color
For i = 1 To lastColumn
If ws.Cells(1, i).Interior.Color = RGB(0, 0, 255) Then
blueColumns(i) = True ' Mark as blue
blueCount = blueCount + 1 ' Increment blue column count
End If
Next i
' If no blue columns found, exit sub
If blueCount = 0 Then Exit Sub
' Set a reference to the current workbook
Set wb = ThisWorkbook
' Create a new worksheet in the current workbook
Set newWs = wb.Sheets.Add
' Name the new worksheet
newWs.Name = "BlueColumns"
' Copy blue columns to the new worksheet
j = 1 ' Initialize new worksheet column index
For i = 1 To lastColumn
If blueColumns(i) Then
' Copy entire column and paste to new worksheet
ws.Columns(i).Copy Destination:=newWs.Columns(j)
j = j + 1 ' Move to the next column in the new worksheet
End If
Next i
' Clear the clipboard
Application.CutCopyMode = False
End Sub
This is also happening with all of my other macros stored in xlsb. Help please I have an urgent deadline!
Last edited by a moderator: