Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Sheet Cleanup Help Please

I have a sheet that has formatting pre set for Columns A:BM. My data key
will be row 1. I need to clear all data in all rows to the right of where
row 1 data ends.

Example:


Col A Col B Col c Col D Col E
Row
1 Data Data Data


Data population ends in Cell C1, Clear all data D:BM.


Col A Col B Col c Col D Col E
Row
1 Data Data Data Data

Data population end in Cell D1, Clear all data E:BM

Can someone help with VBA that will automatically clear this?

Thanks in advance,
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Sheet Cleanup Help Please

Hello again, try the below.

Sub Macro()

Dim lngLastCol1 As Long, lngLastCol2 As Long

lngLastCol1 = Cells(1, Columns.Count).End(xlToLeft).Column
lngLastCol2 = ActiveSheet.Cells.Find(What:="*", _
SearchDirection:=xlPrevious, SearchOrder:=xlByColumns).Column
If lngLastCol2 lngLastCol1 Then
Columns(lngLastCol1 + 1).Resize(, _
lngLastCol2 - lngLastCol1).ClearContents
End If

End Sub


--
Jacob (MVP - Excel)


"BlueAngel" wrote:

I have a sheet that has formatting pre set for Columns A:BM. My data key
will be row 1. I need to clear all data in all rows to the right of where
row 1 data ends.

Example:


Col A Col B Col c Col D Col E
Row
1 Data Data Data


Data population ends in Cell C1, Clear all data D:BM.


Col A Col B Col c Col D Col E
Row
1 Data Data Data Data

Data population end in Cell D1, Clear all data E:BM

Can someone help with VBA that will automatically clear this?

Thanks in advance,

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Sheet Cleanup Help Please


Hello to you.

I couldn't get this to work. Inserted a new module with your code deleted
Cell H1 and run the Macro and cannot see that anything has been cleared. Any
ideas on what I might be doing wrong?


"Jacob Skaria" wrote:

Hello again, try the below.

Sub Macro()

Dim lngLastCol1 As Long, lngLastCol2 As Long

lngLastCol1 = Cells(1, Columns.Count).End(xlToLeft).Column
lngLastCol2 = ActiveSheet.Cells.Find(What:="*", _
SearchDirection:=xlPrevious, SearchOrder:=xlByColumns).Column
If lngLastCol2 lngLastCol1 Then
Columns(lngLastCol1 + 1).Resize(, _
lngLastCol2 - lngLastCol1).ClearContents
End If

End Sub


--
Jacob (MVP - Excel)


"BlueAngel" wrote:

I have a sheet that has formatting pre set for Columns A:BM. My data key
will be row 1. I need to clear all data in all rows to the right of where
row 1 data ends.

Example:


Col A Col B Col c Col D Col E
Row
1 Data Data Data


Data population ends in Cell C1, Clear all data D:BM.


Col A Col B Col c Col D Col E
Row
1 Data Data Data Data

Data population end in Cell D1, Clear all data E:BM

Can someone help with VBA that will automatically clear this?

Thanks in advance,

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Sheet Cleanup Help Please

The below macro will clear the contents..If you want to delete the columns
then replace

..ClearContents

with

..Delete

--
Jacob (MVP - Excel)


"BlueAngel" wrote:


Hello to you.

I couldn't get this to work. Inserted a new module with your code deleted
Cell H1 and run the Macro and cannot see that anything has been cleared. Any
ideas on what I might be doing wrong?


"Jacob Skaria" wrote:

Hello again, try the below.

Sub Macro()

Dim lngLastCol1 As Long, lngLastCol2 As Long

lngLastCol1 = Cells(1, Columns.Count).End(xlToLeft).Column
lngLastCol2 = ActiveSheet.Cells.Find(What:="*", _
SearchDirection:=xlPrevious, SearchOrder:=xlByColumns).Column
If lngLastCol2 lngLastCol1 Then
Columns(lngLastCol1 + 1).Resize(, _
lngLastCol2 - lngLastCol1).ClearContents
End If

End Sub


--
Jacob (MVP - Excel)


"BlueAngel" wrote:

I have a sheet that has formatting pre set for Columns A:BM. My data key
will be row 1. I need to clear all data in all rows to the right of where
row 1 data ends.

Example:


Col A Col B Col c Col D Col E
Row
1 Data Data Data


Data population ends in Cell C1, Clear all data D:BM.


Col A Col B Col c Col D Col E
Row
1 Data Data Data Data

Data population end in Cell D1, Clear all data E:BM

Can someone help with VBA that will automatically clear this?

Thanks in advance,

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Sheet Cleanup Help Please

Does this macro do what you want?

Sub ClearAfterRowOneData()
Dim LastRowOneColumn As Long
LastRowOneColumn = Cells(1, Columns.Count).End(xlToLeft).Column
Columns(LastRowOneColumn + 1).Resize(, 65 - LastRowOneColumn).Clear
End Sub

--
Rick (MVP - Excel)



"BlueAngel" wrote in message
...
I have a sheet that has formatting pre set for Columns A:BM. My data key
will be row 1. I need to clear all data in all rows to the right of where
row 1 data ends.

Example:


Col A Col B Col c Col D Col E
Row
1 Data Data Data


Data population ends in Cell C1, Clear all data D:BM.


Col A Col B Col c Col D Col E
Row
1 Data Data Data Data

Data population end in Cell D1, Clear all data E:BM

Can someone help with VBA that will automatically clear this?

Thanks in advance,




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Sheet Cleanup Help Please

Perhaps I should mention, for clarity sake, that the number 65 in the Resize
property call is the numeric value for Column BM (which was the ending
column that the OP indicated the data should be cleared up to).

--
Rick (MVP - Excel)



"Rick Rothstein" wrote in message
...
Does this macro do what you want?

Sub ClearAfterRowOneData()
Dim LastRowOneColumn As Long
LastRowOneColumn = Cells(1, Columns.Count).End(xlToLeft).Column
Columns(LastRowOneColumn + 1).Resize(, 65 - LastRowOneColumn).Clear
End Sub

--
Rick (MVP - Excel)



"BlueAngel" wrote in message
...
I have a sheet that has formatting pre set for Columns A:BM. My data key
will be row 1. I need to clear all data in all rows to the right of
where
row 1 data ends.

Example:


Col A Col B Col c Col D Col E
Row
1 Data Data Data


Data population ends in Cell C1, Clear all data D:BM.


Col A Col B Col c Col D Col E
Row
1 Data Data Data Data

Data population end in Cell D1, Clear all data E:BM

Can someone help with VBA that will automatically clear this?

Thanks in advance,


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
Data cleanup sjs Excel Worksheet Functions 1 September 16th 09 03:37 PM
SORTING MACRO TO CLEANUP MESSY SHEET stefsailor Excel Programming 10 March 16th 08 02:55 PM
Code cleanup peter.thompson[_53_] Excel Programming 2 January 18th 06 06:16 AM
Code cleanup help please peter.thompson[_8_] Excel Programming 5 December 22nd 05 07:08 AM
Log File CleanUp [email protected][_2_] Excel Programming 1 December 7th 04 06:19 PM


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