Determining Column to Use
Try adding this to your code
Set Rng =Range("1:1").Find(What:="Number", LookIn:=xlValues,
LookAt:=xlWhole, SearchOrder:=xlByColumns, MatchCase:=True
If Not Rng Is Nothing Then Num = Rng.Colum
Set Rng =Range("1:1").Find(What:="Name", LookIn:=xlValues,
LookAt:=xlWhole, SearchOrder:=xlByColumns, MatchCase:=True
If Not Rng Is Nothing Then Nm = Rng.Colum
Rows("4").Columns(Num).Value = New1.TxtNum.Tex
Rows("4").Columns(Nm).Value = New1.TxtName.Tex
----- Dan wrote: ----
I'm trying to avoid referencing specific columns in the VBA code for one of my documents, in case columns are added and whatnot. With one of my bits of code, which adds the current date/time into the currently selected cell, I am using this
If Rows("2").Columns(ActiveCell.Column).Value = "Out" Or
Rows("2").Columns(ActiveCell.Column).Value = "Back" The
initialvar = "DD
I'm using similar code throughout, so that different things are done depending on what column the VBA code is being activated in
Now, my question is, is there a way to take a similar approach to adding information to cells in certain columns, using the header row to determine which column to insert the data? With this code, for ex
Rows("4").Columns("A").Value = New1.TxtNum.Tex
Rows("4").Columns("B").Value = New1.TxtName.Tex
Could I replace ("A") and ("B") with "whatever column has the header of 'Number'" and "whatever column has the header of 'Name'"
Thank
|