首先,如果我的标题术语不正确,我认为这是vba世界的新手。
我正在尝试创建一个宏,它使用匹配函数查找从表单1中的单元格A7开始的值,而不是查找范围a2:“masterlist”中的a1500
然后,它将获取此值以及列的值,该列是基于Sheet1中的值c3与查找范围aa1的查找:“masterlist”中的alr1创建单元格引用然后从sheet1单元格复制值E7到创建的单元格引用。我需要循环直到列a返回一个空白单元格。 E.G从A7到A10工作,基于从A7到A10的参考将值从单元格E7转移到E10到单元格。
我创建了一个我认为可以执行此操作的宏,但每次尝试运行它时都返回error13。
Sub match()
'
' match Macro
'
' Get current state of various Excel settings; put this at the beginning of your code
screenUpdateState = Application.ScreenUpdating
statusBarState = Application.DisplayStatusBar
calcState = Application.Calculation
eventsState = Application.EnableEvents
displayPageBreakState = ActiveSheet.DisplayPageBreaks
' note this is a sheet-level setting
' turn off some Excel functionality so your code runs faster
Application.ScreenUpdating = False
Application.DisplayStatusBar = False
Application.Calculation = xlCalculationManual
Application.EnableEvents = False
ActiveSheet.DisplayPageBreaks = False 'note this is a sheet-level setting
Dim iRow As Integer, d As Integer
iRow = 7
x1 = Application.match(Sheets("Sheet1").Range("B3"), Sheets("Masterlist").Range("AA1:ALR1"), 0) + 26
Do Until IsEmpty(Cells(iRow, 1))
y1 = Application.match(Sheets("Sheet1").Range("A" & iRow), Sheets("Masterlist").Range("A2:A1500"), 0)
Sheets("Masterlist").Select
Cells(x1, y1).Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 65535
.TintAndShade = 0
.PatternTintAndShade = 0
End With
iRow = iRow + 1
Loop
Application.ScreenUpdating = screenUpdateState
Application.DisplayStatusBar = statusBarState
Application.Calculation = calcState
Application.EnableEvents = eventsState
ActiveSheet.DisplayPageBreaks = displayPageBreaksState 'note this is a sheet-level setting
'
End Sub
我理解这是一个用于填充细胞黄色的宏,这是为了减少宏不起作用时的影响。我已经尝试了大部分宏而不是循环并且它可以工作,但是对于循环,我无法让它工作。我希望有人可以对此有所了解。