Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default Clearing contents beyond the "Z" column

Hello,

Below is the code I am using for a button on my sheet.

All works well, but it is not clearing the contents of the new row
beyond column "Z". If I make the k value larger (instead of 1 to 25, I
put 1 to 37 as I want it till column AN) then I get an error and
beyond column "Z" no contents are cleared in the new row.

Any help will be much appreciated! Thank you!

********************

Private Sub CommandButton1_Click()

For i = 1 To 10000
If ActiveSheet.Range("C" & i).Value = "BLENDING FACILITIES"
Then
Range("C" & (i + 1) & ":" & "AN" & (i + 1)).Select
Selection.Copy
Selection.Insert Shift:=xlDown

For k = 1 To 25
If ActiveSheet.Range(Chr(65 + k) & (i + 1)).HasFormula
= False Then
ActiveSheet.Range(Chr(65 + k) & (i +
1)).ClearContents
End If
Next
Exit For
End If
Next

End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Clearing contents beyond the "Z" column


Instead of

For k = 1 To 25
If ActiveSheet.Range(Chr(65 + k) & (i + 1)).HasFormula


For k = 1 to 37
If ActiveSheet.Cells(i+1,k).HasFormula


The Cells member can accept either a letter or number as a column
specifier.

Cordially,
Chip Pearson
Microsoft MVP 1998 - 2010
Pearson Software Consulting, LLC
www.cpearson.com
[email on web site]




On Mon, 15 Feb 2010 10:41:39 -0800 (PST), "Shivam.Shah"
wrote:

Hello,

Below is the code I am using for a button on my sheet.

All works well, but it is not clearing the contents of the new row
beyond column "Z". If I make the k value larger (instead of 1 to 25, I
put 1 to 37 as I want it till column AN) then I get an error and
beyond column "Z" no contents are cleared in the new row.

Any help will be much appreciated! Thank you!

********************

Private Sub CommandButton1_Click()

For i = 1 To 10000
If ActiveSheet.Range("C" & i).Value = "BLENDING FACILITIES"
Then
Range("C" & (i + 1) & ":" & "AN" & (i + 1)).Select
Selection.Copy
Selection.Insert Shift:=xlDown

For k = 1 To 25
If ActiveSheet.Range(Chr(65 + k) & (i + 1)).HasFormula
= False Then
ActiveSheet.Range(Chr(65 + k) & (i +
1)).ClearContents
End If
Next
Exit For
End If
Next

End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default Clearing contents beyond the "Z" column

Thanks a lot! Works perfect!

On Feb 15, 3:13*pm, Chip Pearson wrote:
Instead of

* * * * * *For k = 1 To 25
* * * * * * * *If ActiveSheet.Range(Chr(65 + k) & (i + 1)).HasFormula


For k = 1 to 37
* * * * If ActiveSheet.Cells(i+1,k).HasFormula

The Cells member can accept either a letter or number as a column
specifier.

Cordially,
Chip Pearson
Microsoft MVP 1998 - 2010
Pearson Software Consulting, LLCwww.cpearson.com
[email on web site]

On Mon, 15 Feb 2010 10:41:39 -0800 (PST), "Shivam.Shah"

wrote:
Hello,


Below is the code I am using for a button on my sheet.


All works well, but it is not clearing the contents of the new row
beyond column "Z". If I make the k value larger (instead of 1 to 25, I
put 1 to 37 as I want it till column AN) then I get an error and
beyond column "Z" no contents are cleared in the new row.


Any help will be much appreciated! Thank you!


********************


Private Sub CommandButton1_Click()


* *For i = 1 To 10000
* * * *If ActiveSheet.Range("C" & i).Value = "BLENDING FACILITIES"
Then
* * * * * *Range("C" & (i + 1) & ":" & "AN" & (i + 1)).Select
* * * * * *Selection.Copy
* * * * * *Selection.Insert Shift:=xlDown


* * * * * *For k = 1 To 25
* * * * * * * *If ActiveSheet.Range(Chr(65 + k) & (i + 1)).HasFormula
= False Then
* * * * * * * * * *ActiveSheet.Range(Chr(65 + k) & (i +
1)).ClearContents
* * * * * * * *End If
* * * * * *Next
* * * * * *Exit For
* * * *End If
* *Next


End Sub


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
Convert cell "contents" into a "comment" Ryan Excel Discussion (Misc queries) 4 October 3rd 08 11:34 PM
how to increase size of "name box" and "contents of cell " displa. Stubby- LIBERTY New Users to Excel 2 February 22nd 07 06:43 PM
Please add a "sheet" function like "row" and "column" functions Spreadsheet Monkey Excel Programming 2 November 8th 05 04:08 PM
How do I split "A1B2" into "A1" and "B2" using text to column fun. Jennifer Excel Programming 1 February 2nd 05 10:01 PM
Clearing Contents of all "unprotected" Cells. Casey[_12_] Excel Programming 2 August 6th 04 09:40 PM


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