Moving data between workbooks

Trueblue862

Board Regular
Joined
May 24, 2020
Messages
160
Office Version
  1. 365
Platform
  1. Windows
Hi,
I'm having trouble with this piece of code, I'm trying to search data in one workbook and move it into another workbook to a sheet that is named the same as TbxA.value. It's searching fine but when I try and output the data I can't figure out how to reference the second workbook so it outputs the data there. I have tried numerous ways of referencing the second workbook, but I just can't get it to work. Any help with this would be appreciated.


VBA Code:
Private Const sht1 = "Call Log"
Private Const firstRow_sht1 = 2
Private Const findCol = 1
Private Const inputCol1 = 1
Private Const inputCol2 = 2
Private Const inputCol3 = 3
Private Const inputCol4 = 4
Private Const inputCol5 = 6
Private Const inputCol6 = 7
Private Const inputCol7 = 8




Private sht2 As Variant
Private Const firstRow_sht2 = 1
Private Const outputCol1 = 1
Private Const outputCol2 = 2
Private Const outputCol3 = 3
Private Const outputCol4 = 4
Private Const outputCol5 = 5
Private Const outputCol6 = 6
Private Const outputCol7 = 7




Function outputFunction(output1, output2, output3, output4, output5, output6, output7)


outputRow = Sheets(sht2).Cells(rows.Count, outputCol1).End(xlUp).Row + 1
Sheets(sht2).Cells(outputRow, outputCol1).Value = output1
Sheets(sht2).Cells(outputRow, outputCol2).Value = output2
Sheets(sht2).Cells(outputRow, outputCol3).Value = output3
Sheets(sht2).Cells(outputRow, outputCol4).Value = output4
Sheets(sht2).Cells(outputRow, outputCol5).Value = output5
Sheets(sht2).Cells(outputRow, outputCol6).Value = output6
Sheets(sht2).Cells(outputRow, outputCol7).Value = output7

End Function
Sub SearchData()

sht2 = UCase(Srch_Frm.TbxA.Value)
 textboxA = UCase(Srch_Frm.TbxA.Value) 'Enter your textbox value here.
R = firstRow_sht1
lastRow_sht1 = Sheets(sht1).Cells(rows.Count, findCol).End(xlUp).Row
Do Until R > lastRow_sht1
DoEvents
findValue = UCase(Sheets(sht1).Cells(R, findCol).Value)
If findValue = textboxA Then
output1 = Sheets(sht1).Cells(R, inputCol1).Value
output2 = Sheets(sht1).Cells(R, inputCol2).Value
output3 = Sheets(sht1).Cells(R, inputCol3).Value
output4 = Sheets(sht1).Cells(R, inputCol4).Value
output5 = Sheets(sht1).Cells(R, inputCol5).Value
output6 = Sheets(sht1).Cells(R, inputCol6).Value
output7 = Sheets(sht1).Cells(R, inputCol7).Value



Call outputFunction(output1, output2, output3, output4, output5, output6, output7)
End If
R = R + 1
Loop

 End Sub
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
You may refer here
 
Upvote 0

Forum statistics

Threads
1,215,491
Messages
6,125,109
Members
449,205
Latest member
ralemanygarcia

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