VBA I want to read some data from excel sheet using button. User only enter date and he will get all the details after clicking on button.

1 Answer(s)

Hi, You are not looping through each row in the data sheet (=x, you have not defined what is x in your code). 

I am not quite understand your data in the data sheet, I have written the below code by assuming your data, hope this works:

Private Sub CommandButton1_Click()
lastrow = Sheets("Config_InputAllocation_Weekly").Cells(Rows.Count, 1).End(xlUp).Row
iCntr = 1
For x = 1 To lastrow
If Sheets("Config_InputAllocation_Weekly").Cells(x, 3) = Sheet1.Range("B2") Then
Sheet1.Range("A" & iCntr + 5) = Sheets("Config_InputAllocation_Weekly").Cells(x, 3)
Sheet1.Range("B" & iCntr + 5) = Sheets("Config_InputAllocation_Weekly").Cells(x, 7)
Sheet1.Range("C" & iCntr + 5) = Sheets("Config_InputAllocation_Weekly").Cells(x, 8)
iCntr = iCntr + 1
End If
Next
End Sub

Request: 

  • Please paste the code, instead of screen-shot
  • If possible, please remove the sensitive/confidential data and share your workbook (You can share from your profile, it will be private and only we both can access the file)

Thanks-PNRao!

Keymaster Answered on July 13, 2016.
Add Comment
  • Found this useful?

    Please share using the share button above.

    If you found the answer is best answer for your question, Please mark as 'best answer' by clicking on the right tick mark icon at the left side of the answer.

    Found the answer useful and wants to credit the user, then vote the answer (vote up).

  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.