Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
314 views
in Technique[技术] by (71.8m points)

excel - Dynamical row links for VBA

Does anyone know how to make the row numbers dynamic in my VBA code? For example, Row62 would always reference that particular line item even if a row was inserted above it and is now technically Row63.

The code is currently as follows:

Sub HistoricalMacro()
    Dim c As Long    
    c = Selection.Column

    Application.ScreenUpdating = False     

    'Format cells
    Cells(62, c).NumberFormat = "_(* #,##0_);_(* (#,##0);_(* "" - ""_)"    
    Cells(72, c).NumberFormat = "_(* #,##0_);_(* (#,##0);_(* "" - ""_)"    
    Cells(78, c).NumberFormat = "_(* #,##0_);_(* (#,##0);_(* "" - ""_)"    
    Cells(79, c).NumberFormat = "_(* #,##0_);_(* (#,##0);_(* "" - ""_)"   
     
    'Link cells Expense Summary sheet    
    Cells(55, c).FormulaR1C1 = "='Expense Summary'!R[-1]C"    
    Cells(59, c).Resize(5).FormulaR1C1 = "='Expense Summary'!R[-3]C"    
    Cells(68, c).Resize(5).FormulaR1C1 = "='Expense Summary'!R[-6]C"    
    Cells(76, c).Resize(4).FormulaR1C1 = "='Expense Summary'!R[-9]C"    
     
    'Update expense sum formula    
    Cells(64, c).FormulaR1C1 = "=SUM(R[-5]C:R[-1]C)"    
    Cells(73, c).FormulaR1C1 = "=SUM(R[-5]C:R[-1]C)"    
    Cells(80, c).FormulaR1C1 = "=SUM(R[-4]C:R[-1]C)"
         
    'Clear grey tint in cell    
    Cells(55, c).Resize(25).Interior.ColorIndex = xlColorIndexNone         

    Application.ScreenUpdating = True    
End Sub
question from:https://stackoverflow.com/questions/65839608/dynamical-row-links-for-vba

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...