passing column character as subroutine parameter

A

Anand

I want to pass a column character as parameter to subroutine. What
should I define it as? Also how can I use that inside subroutine?

For example, the API the subroutine should look like is as below:

formatColumn("C") - Should format column C as per defined in the
subroutine. I'm also not clear how I can use this "C" inside
subroutine to identify which column it is. I'm just requested to have
function such as this.

Any suggestions appreciated.

thanks,
Anand.
 
G

Gary''s Student

Sub main()
Dim s As String
s = "D:D"
Call adjustcolumn(s)
End Sub


Sub adjustcolumn(icl As String)
Columns(icl).ColumnWidth = 30
End Sub

We could have made that that passed an integer, but I like your idea better.
Passing a string allows the subroutine to adjust moe than one column at a
time.
 
N

Norman Jones

Hi Anand,

Try something like:

'==========>>
Public Sub Macro1()
Dim sCol As String

sCol = "C"
Call Macro2(sCol)

End Sub

'---------->>
Public Sub Macro2(sColumn As String)
Dim Rng As Range

Set Rng = ActiveSheet.Columns(sColumn)
MsgBox Rng.Address

End Sub
'<<==========
 
A

Anand

Sub main()
Dim s As String
s = "D:D"
Call adjustcolumn(s)
End Sub

Sub adjustcolumn(icl As String)
Columns(icl).ColumnWidth = 30
End Sub

We could have made that that passed an integer, but I like your idea better.
Passing a string allows the subroutine to adjust moe than one column at a
time.


Is there a way I can get the column number from the column passed as
string?

thanks,
Anand.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top