We help IT Professionals succeed at work.
Get Started

Passing column name to function

Shanan212
Shanan212 asked
on
294 Views
Last Modified: 2012-05-12
Sub Macro1(idata As String, iOrig As String)
    Dim iRow As Integer

    iRow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
      
    Columns("F:F").Select
    
    Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
    Range("F2").Select
    ActiveCell.FormulaR1C1 = _
        "=IF(ISERROR(DATE(LEFT(RC[-1],4),MID(RC[-1],5,2),RIGHT(RC[-1],2))),"""",DATE(LEFT(RC[-1],4),MID(RC[-1],5,2),RIGHT(RC[-1],2)))"
   
    Selection.AutoFill Destination:=Range("F2:F" & iRow)
    Range("F2:F" & iRow).Select
    Selection.NumberFormat = "m/dd/yy;@"
    Range("F1").Select
    ActiveCell.FormulaR1C1 = "=RC[-1]"
    Columns("F:F").Select
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Columns("E:E").Select
    Application.CutCopyMode = False
    Selection.Delete Shift:=xlToLeft

End Sub

Open in new window


Hi,

I have the above function but want it to change according to different columns that I would like to send in.

I do  not know how to change the column names accordinly. Say I want to pass

Macro1 ("J", "K")

then I want all the "F" to be changed to "J" and alll the "E" to be changed to "K"

How do I do this change within the function? (specifically below)

    Columns("F:F").Select
    Range("F2:F" & iRow).Select
    Range("F1").Select

Thanks for the help!
Comment
Watch Question
Mechanical Engineer
CERTIFIED EXPERT
Most Valuable Expert 2013
Distinguished Expert 2020
Commented:
This problem has been solved!
Unlock 1 Answer and 5 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE