I am strugglig with the problem. Here is the image 1  after selecting one 
of element in listbox and then if I click delete material (commandbutton).

<https://lh4.googleusercontent.com/-Ug6w5CsWLXE/Uwih9G-fw9I/AAAAAAAAADQ/y2AZDVT_6Zg/s1600/1.png>


It has to delete the select material in sheet 2 and has to cut the element 
below and move to 1 row above as shown in figure 2.

<https://lh6.googleusercontent.com/-1bBsjArpjtA/UwiiLCd1VII/AAAAAAAAADY/fXqZxOSW03E/s1600/2.png>


At the same time it has to delete the entire respective column and 
remaining column has to be cut and place in column before in sheet 3 as 
shown in figure 3

<https://lh3.googleusercontent.com/-qIse4Pe11Is/UwiiQkNYynI/AAAAAAAAADg/SCJwwIcSzZ8/s1600/3.png>


For that I had wrote the program which is below 

Private Sub CommandButton5_Click()

Dim i, j, k, m, n As Integer

i = ListBox1.ListIndex

j = Sheet2.Cells(1, 39).Value

k = j - i

For k = 1 To k

Sheet2.Cells(k + i + 1, 1) = Sheet2.Cells(k + i + 2, 1)

Sheet2.Cells(k + i + 1, 2) = Sheet2.Cells(k + i + 2, 2)

Next k

m = Worksheets("sheet3").Cells(1, i + 2).Value

For m = 1 To m + 2

Worksheets("sheet3").Cells(m, i + 2).ClearContents

Next m

n = Sheet3.Cells(1, i + 3).Value

For k = 1 To k

For n = 1 To n + 2

Sheet3.Cells(n, k + 1 + i) = Sheet3.Cells(n, k + 2 + i)

Next n

Next k

Sheet2.Cells(1, 39).Value = Sheet2.Cells(1, 39).Value - 1

End Sub

 

When I click the delete commandbutton5 the result is as shown in figure 
below

In sheet2

<https://lh4.googleusercontent.com/-OEuwI7DYQKg/UwiiXyOkdPI/AAAAAAAAADo/YnsdDEqd-zg/s1600/4.png>


 

In sheet 3

<https://lh5.googleusercontent.com/-UmqukGxo8GY/Uwiiecb_q1I/AAAAAAAAADw/q_LofuNV1R4/s1600/5.png>


For loop is running only one time after that it got terminated. If I split 
the 1st for loop and execute it.it is running nice what I meant to do. If I 
combine another for loop or If I add msgbox at top it misbehaving. 

I tried with do while loop also it also doing same thing.

Anyone can help me what is the actual mistake I am doing here and how to 
get ride of this problem or suggest me the easier method than this it will 
be helpful.  I am beginner to vba programming ,so if your answer is simple 
and more explanatory manner means very helpful.Thanks in advance

-- 
Are you =EXP(E:RT) or =NOT(EXP(E:RT)) in Excel? And do you wanna be? It’s 
=TIME(2,DO:IT,N:OW) ! Join official Facebook page of this forum @ 
https://www.facebook.com/discussexcel

FORUM RULES

1) Use concise, accurate thread titles. Poor thread titles, like Please Help, 
Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get 
quick attention or may not be answered.
2) Don't post a question in the thread of another member.
3) Don't post questions regarding breaking or bypassing any security measure.
4) Acknowledge the responses you receive, good or bad.
5) Jobs posting is not allowed.
6) Sharing copyrighted material and their links is not allowed.

NOTE  : Don't ever post confidential data in a workbook. Forum owners and 
members are not responsible for any loss.
--- 
You received this message because you are subscribed to the Google Groups "MS 
EXCEL AND VBA MACROS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to excel-macros+unsubscr...@googlegroups.com.
To post to this group, send email to excel-macros@googlegroups.com.
Visit this group at http://groups.google.com/group/excel-macros.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to