Transfering data between Sheets

elmovs

New Member
Joined
Feb 27, 2008
Messages
14
Hi Guys,

Wondering if somebody could give me a hand.

I have one worksheet in which i have the names of companies that have contracted to my company this year. The worksheet has a number of columns but the important ones are Company Name and Contracted.

I then have another worksheet within the same excel document which is in preparation for next year. It has a number of columns also however the important ones in this sheet are Company Name and Previous Exhibitor. The column "previous exhibitor" is a data validation field with the possible options from the list being yes or no.

I need to find a way that will pre populate the 'previous exhibitor' column in the second sheet with the answer 'yes', IF the word contracted appears in the column 'contracted' on the first sheet and obviously matches this with the correct company name. I then need all the other boxes to display 'no'.

I hope this makes sense, if i can help clarify it please let me know. I also have an example spreadsheet made up if anyone is able to have a look at it.

Cheers,

Jr
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Hi, HTH, Fazza

Code:
Sub one_way()
  'For prior to Excel 2007  (modify strConn for Excel 2007)
 
  'Assumes file has been saved at sometime, field headers
  'in first row with data under. Assumed header names are
  '"Company Name", "Contracted" and "Previous Exhibitor"
 
  Const strWksOneName As String = "one worksheet"
  Const strWksOtherName As String = "another worksheet"
 
  Dim strConn As String
  Dim strSQL As String
  Dim objConnection As Object
  Dim objRS As Object
 
  strConn = Join$(Array("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=", _
      ActiveWorkbook.FullName, ";Extended Properties=""Excel 8.0;"""), vbNullString)
 
  strSQL = Join$(Array( _
      "SELECT A.`Company Name`", _
      "FROM [" & strWksOneName & "$] A, [" & strWksOtherName & "$] B", _
      "WHERE A.`Company Name` = B.`Company Name` AND A.`Contracted` = 'contracted'"), vbCr)
 
  Set objRS = CreateObject("ADODB.Recordset")
  objRS.Open strSQL, strConn
 
  Set objConnection = CreateObject("ADODB.Connection")
  With objConnection
    .Open strConn
    .Execute = "UPDATE [" & strWksOtherName & "$] SET `Previous Exhibitor` = 'no'"
 
    Do While Not objRS.EOF
      .Execute "UPDATE [" & strWksOtherName & "$] SET `Previous Exhibitor` = 'yes' WHERE `Company Name`='" & objRS.fields(0).Value & "'"
      objRS.movenext
    Loop
    .Close
  End With
  Set objRS = Nothing
  Set objConnection = Nothing
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,326
Messages
6,124,270
Members
449,149
Latest member
mwdbActuary

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