Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 203
Default Delete columns not required

Hello all, i need some help desperately please !! I am in South Africa
and a spreadsheet gets created in Germany which i download on a daily
basis and manipulate to use in Access. My problem is that they, the
Germans, change the spreadsheet by putting new columns in evry now and
then and then i have to modify my code which takes hours !!

Could i possibly look for the headings that i require, approx. 96
columns, and delete the rest ?

If this is possible or any suggestions i would eternally be gratefull
for some code or suggestions.


Tempy

*** Sent via Developersdex http://www.developersdex.com ***
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Delete columns not required

Sub Processcolumns()
Dim vList as Variant, lastCol as Long
Dim i as Long, res as Variant
vList = Array("Last","First","Middle","Street", _
"City","District","Country", . . . _
"Total","Cat1") 'list a total of 96 column headings found in row 1
lastCol = Cells(1,256).End(xltoLeft).Column
if LastCol = 96 then exit sub
for i = LastCol to 1 step -1
res = Application.Match(cells(1,i),vList,0)
if iserror(res) then
columns(i).Delete
end if
Next
End Sub

--
Regards,
Tom Ogilvy

"Tempy" wrote in message
...
Hello all, i need some help desperately please !! I am in South Africa
and a spreadsheet gets created in Germany which i download on a daily
basis and manipulate to use in Access. My problem is that they, the
Germans, change the spreadsheet by putting new columns in evry now and
then and then i have to modify my code which takes hours !!

Could i possibly look for the headings that i require, approx. 96
columns, and delete the rest ?

If this is possible or any suggestions i would eternally be gratefull
for some code or suggestions.


Tempy

*** Sent via Developersdex http://www.developersdex.com ***



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 203
Default Delete columns not required

Hi Tom, thanks so much for help. As always it is appreciated.

Thanks you

Tempy

*** Sent via Developersdex http://www.developersdex.com ***
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 203
Default Delete columns not required

Hi Tom, I'm sorry, i am not a trained programmer and just want to ask if
the code you gave me is the best way to go or is there another way that
you would suggest ?

regards,

Tempy

*** Sent via Developersdex http://www.developersdex.com ***
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Delete columns not required

My answer was based on the information you provided. I don't know if it is
the best for you or not. What is your concern?

--
Regards,
Tom Ogilvy

"Tempy" wrote in message
...
Hi Tom, I'm sorry, i am not a trained programmer and just want to ask if
the code you gave me is the best way to go or is there another way that
you would suggest ?

regards,

Tempy

*** Sent via Developersdex http://www.developersdex.com ***





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 203
Default Delete columns not required

Sorry, just my mind working overtime, i got some code from the site, i
cant remember who, which saves the names of the different toolbars open
on my spreadsheet in my Macro document and then re-installs them when i
am finished and just wondered if i could have the heading names listed
on sheet1 and then the code looks at the list for thew names required?
I have just tried your code and it deleted the column, however i think
it is the format of the heading it is.. - " Snr Part" and it is wrapped
with the "Snr" above the "Part".
When i look at the format it is text and has a little square after "Snr"
which i asume it is to tell it a space and wrap ?

Tempy

*** Sent via Developersdex http://www.developersdex.com ***
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Delete columns not required

It sounds like you have some non printing characters in the column. The
code as written looks for an exact match, so you can modify it for a partial
match with

Sub Processcolumns()
Dim vList as Variant, lastCol as Long
Dim i as Long, res as Variant
vList = Array("Last","First","Middle","Street", _
"City","District","Country", . . . _
"Total","Cat1") 'list a total of 96 column headings found in row 1
lastCol = Cells(1,256).End(xltoLeft).Column
if LastCol = 96 then exit sub
for i = LastCol to 1 step -1
res = Application.Match("*" & cells(1,i) & "*",vList,0)
if iserror(res) then
columns(i).Delete
end if
Next
End Sub

this might help.

If you wanted to list the column names in a sheet rather than in the array,
let's assume it is in a sheet named List in the workbook containing the
code:

Sub Processcolumns()
Dim vList as Variant, lastCol as Long
Dim i as Long, res as Variant
vList = ThisWorkbooks.Worksheets("List") _
.Range("A1:A96").Value
lastCol = Cells(1,256).End(xltoLeft).Column
if LastCol = 96 then exit sub
for i = LastCol to 1 step -1
res = Application.Match("*" & cells(1,i) & "*",vList,0)
if iserror(res) then
columns(i).Delete
end if
Next
End Sub

You would also have the names listed in row1 as column headings
vList = ThisWorkbooks.Worksheets("List") _
.Range("A1:CR1").Value


--
Regards,
Tom Ogilvy


--
Regards,
Tom Ogilvy

"Tempy" wrote in message
...
Sorry, just my mind working overtime, i got some code from the site, i
cant remember who, which saves the names of the different toolbars open
on my spreadsheet in my Macro document and then re-installs them when i
am finished and just wondered if i could have the heading names listed
on sheet1 and then the code looks at the list for thew names required?
I have just tried your code and it deleted the column, however i think
it is the format of the heading it is.. - " Snr Part" and it is wrapped
with the "Snr" above the "Part".
When i look at the format it is text and has a little square after "Snr"
which i asume it is to tell it a space and wrap ?

Tempy

*** Sent via Developersdex http://www.developersdex.com ***



  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 203
Default Delete columns not required

Hello Tom,I have an exmple of the spreadsheet that i can send to you if
you would like me to.

regards,

Tempy

*** Sent via Developersdex http://www.developersdex.com ***
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
How to count occurrences where 2 columns are required to be true? Brandoni Excel Worksheet Functions 1 November 4th 06 01:26 PM
merge text from 2 columns into 1 then delete the old 2 columns sleepindogg Excel Worksheet Functions 4 March 30th 06 07:25 PM
Delete Columns Jean[_5_] Excel Programming 1 March 5th 04 02:03 PM
Delete columns Elsie Excel Programming 1 February 28th 04 03:08 AM
Delete columns David Excel Programming 1 October 29th 03 01:25 PM


All times are GMT +1. The time now is 10:15 PM.

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

About Us

"It's about Microsoft Excel"