Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 7
Default Retrieving the Column name (e.g. BT) from a numeric


Hi,

I am importing a csv into Excel (Excel 2000) which will have a
varying number of fields in the imported file.

I can loop over a particular row to get the first blank cell in
this row.

As an example, the test file I am using comes back with the first
blank cell as the numeric 72. By looking at the spreadsheet (or by
dividing by 26 plus using the remainder), i can see that this
translates to cell reference BT.

I looked around in the VB help but couldn't find a property (like
say .columname) which would allow me to use this for clearing contents
and formatting the cells within the 'Active' worksheet.

Here is my code to find the last valid column :

For inti = 3 To 256
y = Worksheets("sheet1").Cells(4, inti).Value
If y = "" Then
intlastcol = inti
inti = 257
End If
Next inti

Anyone know if there is such a beast out there ?

Thanks in advance


Niall Heelan
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 367
Default Retrieving the Column name (e.g. BT) from a numeric

Hi Niall,

I'm not sure if this will help you or not, but when I'm doing this type of
thing, I usually use .end(xltoRight).offset(0,1) to find the first empty

You could set up a variable for the empty cell
Dim emptyCell as range

then do this:

set emptyCell = range("A4").end(xltoRight).offset(0,1)

That way you would have a reference to the first empty column and from there
you could hop around wherever you want.

Like I said, I don't know if it will apply to your situation.

Jason

" wrote:


Hi,

I am importing a csv into Excel (Excel 2000) which will have a
varying number of fields in the imported file.

I can loop over a particular row to get the first blank cell in
this row.

As an example, the test file I am using comes back with the first
blank cell as the numeric 72. By looking at the spreadsheet (or by
dividing by 26 plus using the remainder), i can see that this
translates to cell reference BT.

I looked around in the VB help but couldn't find a property (like
say .columname) which would allow me to use this for clearing contents
and formatting the cells within the 'Active' worksheet.

Here is my code to find the last valid column :

For inti = 3 To 256
y = Worksheets("sheet1").Cells(4, inti).Value
If y = "" Then
intlastcol = inti
inti = 257
End If
Next inti

Anyone know if there is such a beast out there ?

Thanks in advance


Niall Heelan

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Retrieving the Column name (e.g. BT) from a numeric

VBA is pretty nice.

You don't need to use letters to refer to a column.

Cells(1,"A")
and
Cells(1,1)
both refer to A1.

dim Inti as long
dim IntLastCol as long
intLastCol = -1
For inti = 3 To 256
y = Worksheets("sheet1").Cells(4, inti).Value
If y = "" Then
intlastcol = inti
exit for
End If
Next inti
if intlastcol = -1 then
'no blanks!
else
.cells(1, intlastcol).entirecolumn.clearcontents
end if

But if you want, here's a way to get the letter/string:

dim ColLetter as string
dim intlastcol as long
intlastcol = 72 'or whatever you find

'this will return something like BT1
colletter = activesheet.cells(1,inlastcol).address(0,0)
'and strip the 1 from the string
colletter = left(colleter, len(colletter)-1)
msgbox colletter



" wrote:

Hi,

I am importing a csv into Excel (Excel 2000) which will have a
varying number of fields in the imported file.

I can loop over a particular row to get the first blank cell in
this row.

As an example, the test file I am using comes back with the first
blank cell as the numeric 72. By looking at the spreadsheet (or by
dividing by 26 plus using the remainder), i can see that this
translates to cell reference BT.

I looked around in the VB help but couldn't find a property (like
say .columname) which would allow me to use this for clearing contents
and formatting the cells within the 'Active' worksheet.

Here is my code to find the last valid column :

For inti = 3 To 256
y = Worksheets("sheet1").Cells(4, inti).Value
If y = "" Then
intlastcol = inti
inti = 257
End If
Next inti

Anyone know if there is such a beast out there ?

Thanks in advance

Niall Heelan


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 7
Default Retrieving the Column name (e.g. BT) from a numeric


Hi Dave,


Thanks for the reply (you too Jason), that's what I was looking
for.


Regards,


Niall Heelan

On Apr 23, 4:17 pm, Dave Peterson wrote:
VBA is pretty nice.

You don't need to use letters to refer to a column.

Cells(1,"A")
and
Cells(1,1)
both refer to A1.

dim Inti as long
dim IntLastCol as long
intLastCol = -1
For inti = 3 To 256
y = Worksheets("sheet1").Cells(4, inti).Value
If y = "" Then
intlastcol = inti
exit for
End If
Next inti
if intlastcol = -1 then
'no blanks!
else
.cells(1, intlastcol).entirecolumn.clearcontents
end if

But if you want, here's a way to get the letter/string:

dim ColLetter as string
dim intlastcol as long
intlastcol = 72 'or whatever you find

'this will return something like BT1
colletter = activesheet.cells(1,inlastcol).address(0,0)
'and strip the 1 from the string
colletter = left(colleter, len(colletter)-1)
msgbox colletter



" wrote:

Hi,


I am importing a csv into Excel (Excel 2000) which will have a
varying number of fields in the imported file.


I can loop over a particular row to get the first blank cell in
this row.


As an example, the test file I am using comes back with the first
blank cell as the numeric 72. By looking at the spreadsheet (or by
dividing by 26 plus using the remainder), i can see that this
translates to cell reference BT.


I looked around in the VB help but couldn't find a property (like
say .columname) which would allow me to use this for clearing contents
and formatting the cells within the 'Active' worksheet.


Here is my code to find the last valid column :


For inti = 3 To 256
y = Worksheets("sheet1").Cells(4, inti).Value
If y = "" Then
intlastcol = inti
inti = 257
End If
Next inti


Anyone know if there is such a beast out there ?


Thanks in advance


Niall Heelan


--

Dave Peterson


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
find alpha in column 1 numeric column 2 JANeyer Excel Discussion (Misc queries) 2 February 26th 08 04:44 AM
How do I format the A/ B Column to be fixed like numeric column RYarn Excel Worksheet Functions 1 August 17th 07 02:18 AM
How do I format the A/ B Column to be fixed like numeric column April Excel Worksheet Functions 0 August 17th 07 01:57 AM
Find Numeric Criterion in Column & Return the Numeric Value from Row above Sam via OfficeKB.com Excel Worksheet Functions 6 April 27th 06 02:50 PM
Retrieving data from a corresponding row from a different column fluci Excel Discussion (Misc queries) 3 October 27th 05 05:38 AM


All times are GMT +1. The time now is 02:54 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"