PC Review


Reply
Thread Tools Rate Thread

Delete columns based on a cell reference date value

 
 
fishy
Guest
Posts: n/a
 
      18th Nov 2009
I have a sheet titled 'data' that has source information and row 1 has
columns H to BG with dates.

On sheet 'Control' is a cell that has a free format cell for dates to be
entered. I have named this cell 'WCDATA' for ease of another piece of code.

I am tring to create a macro that will locate the date specified in WCDATA
on the data sheet and delete all columns from H until that which matches
WCDATA.

Fortunately I have been running on a test file and I have tried several
options but after considerable hair pulling am seeking assistance as am
getting close to deadline now.

Any assistance appreciated.

R
 
Reply With Quote
 
 
 
 
Jarek Kujawa
Guest
Posts: n/a
 
      18th Nov 2009
Sub cus()
Dim cell As Range
For i = Range("H1").Column To Worksheets("data").Range
("H1:BG1").Cells.Count
If Cells(1, i).Value <> Range("WCDATA").Value Then
Cells(1, i).Columns.EntireColumn.Delete
i = i - 1
Else
Exit For
End If
Next i

End Sub


On 18 Lis, 08:59, fishy <fi...@discussions.microsoft.com> wrote:
> I have a sheet titled 'data' that has source information and row 1 has
> columns H to BG with dates.
>
> On sheet 'Control' is a cell that has a free format cell for dates to be
> entered. I have named this cell 'WCDATA' for ease of another piece of code.
>
> I am tring to create a macro that will locate the date specified in WCDATA
> on the data sheet and delete all columns from H until that which matches
> WCDATA.
>
> Fortunately I have been running on a test file and I have tried several
> options but after considerable hair pulling am seeking assistance as am
> getting close to deadline now.
>
> Any assistance appreciated.
>
> R


 
Reply With Quote
 
Jarek Kujawa
Guest
Posts: n/a
 
      18th Nov 2009
corrected

Sub cus()

For i = Range("H1").Column To Worksheets("data").Range
("H1:BG1").Cells.Count
Cells(1, i).Activate
If Cells(1, i).Value <> Range("WCDATA").Value Then
Cells(1, i).Columns.EntireColumn.Delete
i = i - 1
Else
Exit For
End If
Next i

End Sub

On 18 Lis, 08:59, fishy <fi...@discussions.microsoft.com> wrote:
> I have a sheet titled 'data' that has source information and row 1 has
> columns H to BG with dates.
>
> On sheet 'Control' is a cell that has a free format cell for dates to be
> entered. I have named this cell 'WCDATA' for ease of another piece of code.
>
> I am tring to create a macro that will locate the date specified in WCDATA
> on the data sheet and delete all columns from H until that which matches
> WCDATA.
>
> Fortunately I have been running on a test file and I have tried several
> options but after considerable hair pulling am seeking assistance as am
> getting close to deadline now.
>
> Any assistance appreciated.
>
> R


 
Reply With Quote
 
Jacob Skaria
Guest
Posts: n/a
 
      18th Nov 2009
You can avoid that looping

Sub Macro8()
Dim varfound As Range
Set varfound = Worksheets("Data").Rows(1).Find(Range("wcdata"))
If Not varfound Is Nothing Then
Worksheets("Data").Range("H1", Cells(1, varfound.Column)).EntireColumn.Delete
End If
End Sub

If this post helps click Yes
---------------
Jacob Skaria


"Jarek Kujawa" wrote:

> corrected
>
> Sub cus()
>
> For i = Range("H1").Column To Worksheets("data").Range
> ("H1:BG1").Cells.Count
> Cells(1, i).Activate
> If Cells(1, i).Value <> Range("WCDATA").Value Then
> Cells(1, i).Columns.EntireColumn.Delete
> i = i - 1
> Else
> Exit For
> End If
> Next i
>
> End Sub
>
> On 18 Lis, 08:59, fishy <fi...@discussions.microsoft.com> wrote:
> > I have a sheet titled 'data' that has source information and row 1 has
> > columns H to BG with dates.
> >
> > On sheet 'Control' is a cell that has a free format cell for dates to be
> > entered. I have named this cell 'WCDATA' for ease of another piece of code.
> >
> > I am tring to create a macro that will locate the date specified in WCDATA
> > on the data sheet and delete all columns from H until that which matches
> > WCDATA.
> >
> > Fortunately I have been running on a test file and I have tried several
> > options but after considerable hair pulling am seeking assistance as am
> > getting close to deadline now.
> >
> > Any assistance appreciated.
> >
> > R

>
> .
>

 
Reply With Quote
 
Jarek Kujawa
Guest
Posts: n/a
 
      19th Nov 2009
thks Jacob

On 18 Lis, 10:17, Jacob Skaria <JacobSka...@discussions.microsoft.com>
wrote:
> You can avoid that looping
>
> Sub Macro8()
> Dim varfound As Range
> Set varfound = Worksheets("Data").Rows(1).Find(Range("wcdata"))
> If Not varfound Is Nothing Then
> Worksheets("Data").Range("H1", Cells(1, varfound.Column)).EntireColumn.Delete
> End If
> End Sub
>
> If this post helps click Yes
> ---------------
> Jacob Skaria
>
>
>
> "Jarek Kujawa" wrote:
> > corrected

>
> > Sub cus()

>
> > For i = Range("H1").Column To Worksheets("data").Range
> > ("H1:BG1").Cells.Count
> > Cells(1, i).Activate
> > If Cells(1, i).Value <> Range("WCDATA").Value Then
> > Â* Â*Cells(1, i).Columns.EntireColumn.Delete
> > Â* Â*i = i - 1
> > Else
> > Â* Â*Exit For
> > End If
> > Next i

>
> > End Sub

>
> > On 18 Lis, 08:59, fishy <fi...@discussions.microsoft.com> wrote:
> > > I have a sheet titled 'data' that has source information and row 1 has
> > > columns H to BG with dates.

>
> > > On sheet 'Control' is a cell that has a free format cell for dates tobe
> > > entered. I have named this cell 'WCDATA' for ease of another piece ofcode.

>
> > > I am tring to create a macro that will locate the date specified in WCDATA
> > > on the data sheet and delete all columns from H until that which matches
> > > WCDATA.

>
> > > Fortunately I have been running on a test file and I have tried several
> > > options but after considerable hair pulling am seeking assistance as am
> > > getting close to deadline now.

>
> > > Any assistance appreciated.

>
> > > R

>
> > .- Ukryj cytowany tekst -

>
> - Pokaż cytowany tekst -


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
delete columns based on value in one cell larrydave Microsoft Excel Programming 7 11th Dec 2008 03:37 AM
Delete columns based on cell value Robert H Microsoft Excel Programming 6 1st Feb 2007 01:40 PM
Cell Formula reference to cell Based On third Cell Content =?Utf-8?B?R2FicmllbA==?= Microsoft Excel Misc 1 11th Feb 2005 06:36 AM
Cell Formula reference to cell Based On third Cell Content =?Utf-8?B?R2FicmllbA==?= Microsoft Excel Misc 0 11th Feb 2005 05:35 AM
Reference a workbook based on a cell reference douga Microsoft Excel Worksheet Functions 1 17th Feb 2004 06:21 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:02 PM.