Hello,
(Edited for Forum Rule #3 compliance -- sorry about that)
I'm a newbie to VBA programming, but am pretty experienced with Excel formulas. I'm attempting to invoke the VLOOKUP worksheet function in a macro I am writing (see last 7 lines of my code below), but each time I run I get the Method 'Range' of object '_Global' failed error.
("lookuptab" is a named range already defined in the workbook.)
Any help would be appreciated. Again, I'm new to VBA, so I'm sure it's some basic misunderstanding on my part.
Thanks in advance,
Jim
Sub reformat1()
'
' reformat1 Macro
'
'
Dim NumCols As Integer, NumRows As Integer
Rows("11:11").Select
Selection.Find(What:="Team Member Mean", After:=ActiveCell, LookIn:=xlFormulas _
, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
NumCols = ActiveCell.Column
Columns("a:a").Select
Selection.Find(What:="Grand Total", After:=ActiveCell, LookIn:=xlFormulas _
, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
NumRows = ActiveCell.Row
Range(Cells(NumRows, 1), Cells(NumRows, NumCols)).Select
With Selection.Interior
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorDark1
.TintAndShade = -0.149998474074526
.PatternTintAndShade = 0
End With
With Selection
.NumberFormat = "0.0"
.Font.Bold = True
End With
Range(Cells(11, NumCols), Cells(NumRows, NumCols)).Select
With Selection.Interior
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorDark1
.TintAndShade = -0.149998474074526
.PatternTintAndShade = 0
End With
With Selection
.NumberFormat = "0.0"
.Font.Bold = True
End With
Cells(11, NumCols).Select
ActiveCell.Value = "Team Member Mean"
Cells(11, NumCols + 1).Select
ActiveCell.Value = "Overall Satisfaction w/CVS Caremark"
Range(Cells(11, NumCols + 1), Cells(NumRows, NumCols + 1)).Select
With Selection.Interior
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorDark1
.TintAndShade = -0.149998474074526
.PatternTintAndShade = 0
End With
With Selection
.NumberFormat = "0.0"
.Font.Bold = True
End With
Range(Cells(11, 2), Cells(NumRows, NumCols + 1)).Select
Selection.ColumnWidth = 11
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = True
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Dim cell As Range
Dim ltab As Range
Set ltab = Range("lookuptab")
For Each cell In Range(Cells(12, NumCols + 1), Cells(NumRows - 1, NumCols + 1))
cell = Worksheet.Function.VLookup((Range("cell").Offset(0, 0 - NumCols)), ltab, 109, False)
Next cell
End Sub
Bookmarks