Forum Discussion

rodsan724's avatar
rodsan724
Brass Contributor
Oct 29, 2021

I've got hardcoded ranges in my vba code, what's the best practice

Hi,

I'm using Excel 2016 and have some VBA code in my workbook. I've got hardcoded addresses like the following throughout my code. When I add or remove columns, I have to go in and find them and then change them. Is there a better way to maintain these strings?

 

 

Range("T2:AE2").Select 'TODO: Column changes

 

 

1 Reply

  • mathetes's avatar
    mathetes
    Silver Contributor

    rodsan724 

     

    Why are you adding and removing columns in the first place? What do the new ones represent? What happened to the discarded ones? What's the nature of the data being collected?

     

    I'm asking these questions to try to get at the original design, thinking that there may be a different way altogether, having to do with what the workbook is about and whether you could design it differently.

Resources