Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2
Default Excel macro to insert uncertain numbers of column with different value

Hi

I have a work sheet as below:

Column1 Column2 Column3 Colum4 Column5 Column6
row1 C Y C C_c2 C_c3
END
row2 C N END

For each row in the worksheet, I have to check the Column2,
if the value is "Y",
then I will need to insert 3 columns to the worksheet,
for example, initially row1 is C N END,(three columns only)
After I change the column2 to Y and run the macro, it should change to
C, Y, C, C_c2, C_c3 END.(Six columns)

Similary, for every row, if I change the Column2 value from "Y" to
"N", It should delete next 3 columns after column2.
For example, Initially row1 is C Y C C_c2 C_c3 END,
If i change the Y to N, It should become C N END

Can I get some help to write the excel macro for this?
Thanks in advance!

regards,
Kai

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 9,101
Default Excel macro to insert uncertain numbers of column with different v

Add this code to your worksheet. On the tab on the bottom of the worksheet
click right mouse button and select view code. Copy and paste code shown
below

Private Sub Worksheet_change(ByVal Target As Range)


If Target.Column = 2 Then
If (StrComp(Target, "y") = 0) Or _
(StrComp(Target, "Y") = 0) Then


Columns("C:E").Insert Shift:=xlToRight

Else

If (StrComp(Target, "n") = 0) Or _
(StrComp(Target, "N") = 0) Then

Columns("C:E").Delete Shift:=xlToLeft

End If
End If


End If

End Sub


" wrote:

Hi

I have a work sheet as below:

Column1 Column2 Column3 Colum4 Column5 Column6
row1 C Y C C_c2 C_c3
END
row2 C N END

For each row in the worksheet, I have to check the Column2,
if the value is "Y",
then I will need to insert 3 columns to the worksheet,
for example, initially row1 is C N END,(three columns only)
After I change the column2 to Y and run the macro, it should change to
C, Y, C, C_c2, C_c3 END.(Six columns)

Similary, for every row, if I change the Column2 value from "Y" to
"N", It should delete next 3 columns after column2.
For example, Initially row1 is C Y C C_c2 C_c3 END,
If i change the Y to N, It should become C N END

Can I get some help to write the excel macro for this?
Thanks in advance!

regards,
Kai


  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2
Default Excel macro to insert uncertain numbers of column with different v

Thanks man, but it seems not working...

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
Is there a way to insert dashes in a column of numbers Mickie New Users to Excel 7 April 30th 23 11:43 AM
how do I quickly insert numbers 1 to 100 in a column in Excel? Terri Excel Discussion (Misc queries) 7 April 2nd 23 04:27 PM
Excel Macro to Insert the contents of one column to other Dhawal Excel Discussion (Misc queries) 5 October 5th 06 01:22 PM
How to insert text in one column and populate numbers in another Alice Excel Worksheet Functions 0 March 28th 06 07:27 PM
How do I insert the degree symbol in a column of numbers? JKB Excel Discussion (Misc queries) 3 July 6th 05 07:17 AM


All times are GMT +1. The time now is 05:35 AM.

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"