Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 208
Default Deleting columns other than those that a specific word in row A

I have a requirement to delete columns in my spreadsheet based upon the value
that appears in column A. I recentlt posted a similar request on here and
got the following suggestion:

Sub Valuation()

' Dim rng as Range, sStr as String, i as Long
Set Rng = Cells(1, "IV").End(xlToLeft)
For i = Rng.Column To 1 Step -1
sStr = LCase(Cells(1, i).Value)
If sStr < "fondsname" And _
sStr < "wertpapierkurzbez" And _
sStr < "gw wpi isin" And _
sStr < "stücke/nominale" And _
sStr < "effektenkurs" And _
sStr < "kurswert in bw" And _
sStr < "offene forderungen" Then
Cells(1, i).EntireColumn.Delete
End If
Next

End Sub

I used a variation of this on other spreadsheets and it worked fine,
however, wehen I used the strings that I have used above i run into problems
and I don't get the result i am hoping for. I believe that there may be
hidden spaces within the cell or something. Does anyone know how to get
around the problem ?

Thanks



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default Deleting columns other than those that a specific word in row A

I think you're going to have to share some more information.

What bad things happen/don't happen when you run your code?

If a column is being deleted that should be kept, what was in row 1 of that
column?

If a column is being kept that should be deleted, what was in row 1 of that
column?

If there are extra spaces, maybe you could trim() the values.

sstr = trim(lcase(cells(1,i).value))



Sean wrote:

I have a requirement to delete columns in my spreadsheet based upon the value
that appears in column A. I recentlt posted a similar request on here and
got the following suggestion:

Sub Valuation()

' Dim rng as Range, sStr as String, i as Long
Set Rng = Cells(1, "IV").End(xlToLeft)
For i = Rng.Column To 1 Step -1
sStr = LCase(Cells(1, i).Value)
If sStr < "fondsname" And _
sStr < "wertpapierkurzbez" And _
sStr < "gw wpi isin" And _
sStr < "stücke/nominale" And _
sStr < "effektenkurs" And _
sStr < "kurswert in bw" And _
sStr < "offene forderungen" Then
Cells(1, i).EntireColumn.Delete
End If
Next

End Sub

I used a variation of this on other spreadsheets and it worked fine,
however, wehen I used the strings that I have used above i run into problems
and I don't get the result i am hoping for. I believe that there may be
hidden spaces within the cell or something. Does anyone know how to get
around the problem ?

Thanks


--

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
Deleting a Row if it contains a specific word Steve Madsen Excel Discussion (Misc queries) 1 February 1st 07 09:58 PM
Link from a specific Cell in Excel to a specific para. in Word CathyK Excel Worksheet Functions 0 August 10th 06 04:40 PM
Linking a Specific Word to a Specific Number [email protected] Excel Worksheet Functions 2 July 11th 06 05:50 PM
Linking a Specific Word to a Specific Number [email protected] Excel Worksheet Functions 1 July 11th 06 04:29 PM
Count If Specific word in specific range [email protected] Excel Discussion (Misc queries) 2 May 16th 06 10:14 AM


All times are GMT +1. The time now is 01: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"