new record on new row line?

PANKAJUTEKAR

Board Regular
Joined
Jun 10, 2011
Messages
79
Dear Sir,

In following coding, when i am click on comd bttn the data is saved in (e4:j4).

now the problem is,
1). when i am try to add a new data on the next row, it is not coming.
2). as the comd bttn is used, the comd btn add the record in all rows whatever mentioned.

So i require help from VBA Gurus to solve the problem.

Private Sub CommandButton4_Click()
Call addrecord
ThisWorkbook.Activate
End Sub

Sub addrecord()
Dim i As Integer, j As Integer, k As Integer
Do Until j = 10
i = 4
j = 5
Cells(i, j) = Cells(5, 3)
j = j + 1
Cells(i, j) = Cells(10, 3)
j = j + 1
Cells(i, j) = Cells(18, 3)
j = j + 1
Cells(i, j) = Cells(19, 3)
j = j + 1
Cells(i, j) = Cells(21, 3)
j = j + 1
Cells(i, j) = Cells(22, 3)
Loop
Range("c5,c10,c18,c19,c21,c22").Select
Selection.ClearContents
End Sub
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Your loop is executed once 'cause in the end of the loop j = 10, and loop is terminated.
This is the same as if you'd delete Do Until and Loop statements.
 
Last edited:
Upvote 0
I don't understand; you're looping with an end condition that J=10, yet within the loop you set J to 5 and then add 1 5 times, so by the time execution gets to the LOOP statement J will always be 10, so the do...loop is irrelevant
 
Upvote 0
i don't understand; you're looping with an end condition that j=10, yet within the loop you set j to 5 and then add 1 5 times, so by the time execution gets to the loop statement j will always be 10, so the do...loop is irrelevant

sir,

can u have better idea to crack this?
 
Upvote 0
sir,

can u have better idea to crack this?

===============
Dear Sir,

Wht i m looking for that-
- i took comd bttn.
- there are cells c5, c10, c18, c19, c21, c22. This cell contains data.
- when i am click on comd bttn, this cell data goes into e4:j4.
- now whn i am taking another record in cells c5, c10, c18, c19, c21, c22. (This is user input)
- This data should go on e5:j5 and the same every new record save on e6:j6.....en:jn. like this.

Now i didnt get that how i recognize the row?
should i use for loop for row or wht?
 
Upvote 0
Code:
Sub AddRecord()
    
    Dim lastRow As Long, arr As Variant
    
    lastRow = Cells(Rows.Count, "E").End(xlUp).Row + 1
    If lastRow = 2 Then lastRow = 4
    
    arr = Array(Cells(5, 3), Cells(10, 3), Cells(18, 3), Cells(19, 3), Cells(21, 3), Cells(22, 3))
    Cells(lastRow, 5).Resize(, 6) = arr
    
    Range("C5,C10,C18,C19,C21,C22").ClearContents
    
 End Sub
 
Upvote 0

Forum statistics

Threads
1,224,538
Messages
6,179,412
Members
452,912
Latest member
alicemil

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top