I have the following macro that will search for three different column headings, select the data under those headings and change the data from a currency format to a number format. The data is stored in Sheet 2 of my workbook and the macro works fine when I run it on it's own in this Sheet.
Sub ProjectFundingFormat()
'
Dim WS As Worksheet
Dim lastCol As Long, lastRow As Long, srcRow As Range
Dim found1 As Range, found2 As Range
Set WS = Workbooks("Workbook1.xlsm").Worksheets("Sheet2") 'Needs to be open
With WS
lastCol = .Cells(1, Columns.count).End(xlToLeft).Column
Set srcRow = .Range("A1", .Cells(1, lastCol))
Set found1 = srcRow.Find(What:="2018FundingLabor", LookAt:=xlWhole, MatchCase:=False)
If Not found1 Is Nothing Then
lastRow = .Cells(Rows.count, found1.Column).End(xlUp).Row
.Range(.Cells(2, found1.Column), .Cells(lastRow, found1.Column)).Select
Selection.NumberFormat = "0.00"
End If
End With
With WS
lastCol = .Cells(1, Columns.count).End(xlToLeft).Column
Set srcRow = .Range("A1", .Cells(1, lastCol))
Set found1 = srcRow.Find(What:="2018FundingNonlabor", LookAt:=xlWhole, MatchCase:=False)
If Not found1 Is Nothing Then
lastRow = .Cells(Rows.count, found1.Column).End(xlUp).Row
.Range(.Cells(2, found1.Column), .Cells(lastRow, found1.Column)).Select
Selection.NumberFormat = "0.00"
End If
End With
With WS
lastCol = .Cells(1, Columns.count).End(xlToLeft).Column
Set srcRow = .Range("A1", .Cells(1, lastCol))
Set found1 = srcRow.Find(What:="2018 Total Funding", LookAt:=xlWhole, MatchCase:=False)
If Not found1 Is Nothing Then
lastRow = .Cells(Rows.count, found1.Column).End(xlUp).Row
.Range(.Cells(2, found1.Column), .Cells(lastRow, found1.Column)).Select
Selection.NumberFormat = "0.00"
End If
End With
End Sub
I am wanting to combine this macro with another two so that I can go into Sheet 1, click a "run" button I have inserted and all my macros will run together to update my data.
However, I am getting the error
Run time error 1004 - select method of range class failed
at the line
.Range(.Cells(2, found1.Column), .Cells(lastRow, found1.Column)).Select
Does anyone know what might be wrong with my code? I am confused since it works fine on its own, but won't run when combined with my other macros.
I am using the following macro to combine my two existing macros:
Sub ProjectUpdate()
Call ProjectName
Call ProjectFunding
Call ProjectFundingFormat
MsgBox "Done"
End Sub