Need help in writing formula for the query????

tv9_rohith

Board Regular
Joined
Sep 1, 2011
Messages
96
In the Spreadsheet I have 2 Sheets.

1sheett for the Complete information about the Employee - Name, Location, Sex, Job Role, Salary.

2sheet only the required fields are - Name, Location, Job Role.

My query is :

If I enter data in the sheet 1 and I click the Command Button in Sheet 1 ( i.e., Generate Report Button ) then automatically the required column information should display in Sheet 2.

For example I have enterd 6 rows of data in sheet1 then all the 6 rows information should display in Sheet 2.
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Hi,
So you just want the data entered on sheet1 to be copied to sheet2? at the bottom of exsisting data?
 
Upvote 0
what ever I enter in the sheet 1 it should display in the sheet 2 but I dnt require all the columns but only few.

for example

in sheet 1 there are columns like this - Name, Sex, location , Age, Salary.

in sheet 2 I need only Name,location and salary.


when I enter the data in sheet1 and click on the Commmand button it should through the information to sheet 2
 
Upvote 0
hi,

if it is a formula for cells that get replaced

on sheet2 a1 enter

=sheet1!A1

this will make sheet2 a1 = sheet1 a1 (change as needed for coloums)

if you are after VBA

Code:
dim count as long
dim count2 as long
dim counta as long
 
 
counta = 1 
 
count = sheets("Sheet1").Range("A1").CurrentRegion.Rows.count
count2 = sheets("Sheet2").Range("A1").CurrentRegion.Rows.count 
 
do until counta = count
count2=count2 + counta
sheets("Sheet2").range("A" & count2).value =  sheets("Sheet1").range("A" & counta).value
 
'repeat the above for the coloums you want making sure to match them, ie if name is on sheet 1 in A then it is A on sheet2 (or whereever you have it)
counta = counta + 1
loop
 
Last edited:
Upvote 0
when I use the below mentioned formula then in the sheet2 I getting data but include the header value and hender value and the 2 value is coming with 1 cell blank in the middle ( same row ) and the 2 value and the 3 rd value are having 2 blanks in the middle and its increasing the blank cell between the cells to 3, 4, 5, 6

dim count as long
dim count2 as long
dim counta as long


counta = 1

count = sheets("Sheet1").Range("A1").CurrentRegion.Rows.count
count2 = sheets("Sheet2").Range("A1").CurrentRegion.Rows.count

do until counta = count
count2=count2 + counta
sheets("Sheet2").range("A" & count2).value = sheets("Sheet1").range("A" & counta).value

'repeat the above for the coloums you want making sure to match them, ie if name is on sheet 1 in A then it is A on sheet2 (or whereever you have it)
counta = counta + 1
loop
 
Upvote 0
change the below

Code:
count = sheets("Sheet1").Range("A2").CurrentRegion.Rows.count
count2 = sheets("Sheet2").Range("A2").CurrentRegion.Rows.count

and also

Code:
counta = 2

give that a try and let me know
 
Upvote 0
As per your advice I have tried with the below mentioned Code but only the thing that error has rectified is Header is not coming in the sheet 2 but the gaps between cells is increasing and the last value in sheet 1 is not at all coming in sheet2

dim count as long
dim count2 as long
dim counta as long

counta = 2
count = sheets("Sheet1").Range("A2").CurrentRegion.Rows.count
count2 = sheets("Sheet2").Range("A2").CurrentRegion.Rows.count
do until counta = count
count2=count2 + counta
sheets("Sheet2").range("A" & count2).value = sheets("Sheet1").range("A" & counta).value
'repeat the above for the coloums you want making sure to match them, ie if name is on sheet 1 in A then it is A on sheet2 (or whereever you have it)
counta = counta + 1
loop

Could you please check it.
 
Upvote 0
when I try with the below mentioned code I getting error :

Run Time error '1004':

Application - defined or object -defined error

and the formula I have pasted is :
Private Sub CommandButton1_Click()
Dim count As Long
Dim count2 As Long
Dim counta As Long
count2 = counta
count = Sheets("Sheet2").Range("D2").CurrentRegion.Rows.count
count2 = Sheets("Sheet3").Range("A2").CurrentRegion.Rows.count
Do Until counta = count
count2 = count2 + counta
Sheets("Sheet3").Range("A" & count2).Value = Sheets("Sheet2").Range("D" & counta).Value
counta = counta + 1
Loop
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,581
Messages
6,179,668
Members
452,936
Latest member
anamikabhargaw

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