Copy & Paste Data Depending On another Cell's Value

nick1408

Board Regular
Joined
Jan 18, 2010
Messages
80
Hi Guys,

I've hit a bit of a wall. I'm trying to copy & paste calls depending on the value of another cell in the same row. So far I have this:

Code:
Do Until IsEmpty(ActiveCell)
If Sheets("Data").Range("G" & ActiveCell.Row).Value = Sheets("Rack A").Range(ActiveCell.Column & "1").Value Then
ActiveCell.Copy
ActiveCell.Offset(1, 0).Select
Worksheets("Rack A").Select
ActiveCell.PasteSpecial
Worksheets("Data").Select
ActiveCell.Offset(1, 0).Select
Else
ActiveCell.EntireRow.Copy
Worksheets("FloorRoomWorkstation No Update").Select
ActiveCell.PasteSpecial
ActiveCell.Offset(1, 0).Select
Worksheets("Data").Select
ActiveCell.Offset(1, 0).Select
End If
      Loop

I'm getting an error on the second row (the if statement). In basic terms what I am after is if the G column of the active row in sheet "Data" matches the active column, row 1 in sheet "Rack A" then paste the active cell in "Data" to the active cell in "Rack A".

Thanks guys
 
Last edited:

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.

My Aswer Is This

Well-known Member
Joined
Jul 5, 2014
Messages
19,343
Office Version
  1. 2021
Platform
  1. Windows
#1 You have not shown us your entire script. Please show us your entire script
#2 Please tell us in words what your wanting to do and do not use the term active cell.

When doing loops we do not normally use the term active cell.

And tell us what column not the active column

Tell us what your ultimate goal is and do not tell us how to achieve the goal

Look forward to hearing back from you.
 
Upvote 0

nick1408

Board Regular
Joined
Jan 18, 2010
Messages
80
#1 You have not shown us your entire script. Please show us your entire script
#2 Please tell us in words what your wanting to do and do not use the term active cell.

When doing loops we do not normally use the term active cell.

And tell us what column not the active column

Tell us what your ultimate goal is and do not tell us how to achieve the goal

Look forward to hearing back from you.

#1 The above is almost the entire code - I left out some comments:
Code:
Sub updateLocations()
'clear sheets
'Worksheets("Rack A").Select
'Rows("3:" & Rows.Count).ClearContents
'Worksheets("Rack b").Select
'Rows("3:" & Rows.Count).ClearContents
'Worksheets("Rack c").Select
'Rows("3:" & Rows.Count).ClearContents
'Worksheets("Cage").Select
'Rows("3:" & Rows.Count).ClearContents
'Worksheets("FloorRoomWorkstation No Update").Select
'Rows("3:" & Rows.Count).ClearContents
'update cells
'Rack A Code
Worksheets("Rack A").Select
Range("A3").Select
Worksheets("Data").Select
Range("A2").Select
Do Until IsEmpty(ActiveCell)
If Sheets("Data").Range("G" & ActiveCell.Row).Value = Sheets("Rack A").Range(ActiveCell.Column & "1").Value Then
ActiveCell.Copy
ActiveCell.Offset(1, 0).Select
Worksheets("Rack A").Select
ActiveCell.PasteSpecial
Worksheets("Data").Select
ActiveCell.Offset(1, 0).Select
Else
ActiveCell.EntireRow.Copy
Worksheets("FloorRoomWorkstation No Update").Select
ActiveCell.PasteSpecial
ActiveCell.Offset(1, 0).Select
Worksheets("Data").Select
ActiveCell.Offset(1, 0).Select
End If
      Loop
'Rack B Code
'Rack C Code
'Cage Code
End Sub
#2 I want the flow to go like this:
- Does Sheets("Rack A").(Range("A1") = Sheets("Data").Range("G2")?
- If true copy Sheets("Data").Range("A2") to Sheets("Rack A").Range("A3")
- Activecell.offset(1,0).select on both sheets
- If false copy Sheets("Data") row 2 to Sheets("FloorRoomWorkstation No Update")
- Activecell.offset(1,0).select both sheets
- Loop
- Does Sheets("Rack A").(Range("A1") = Sheets("Data").Range("G3")?
- If true copy Sheets("Data").Range("A3") to Sheets("Rack A").Range("A4")
- Activecell.offset(1,0).select on both sheets
- If false copy Sheets("Data") row 3 to Sheets("FloorRoomWorkstation No Update")
- Activecell.offset(1,0).select both sheets
-Loop

And so on

Then do the same for the B column on "Rack A", then the C column and so on but I haven't added this part yet.
 
Upvote 0

My Aswer Is This

Well-known Member
Joined
Jul 5, 2014
Messages
19,343
Office Version
  1. 2021
Platform
  1. Windows
Thank you for your response and I'm going to let someone else here at Mr. Excel help you.
I asked for your ultimate Goal and you listed off a series of instructions on how to do it.

For example:
Activecell.offset(1,0).select on both sheets

See your telling me how to do it.

And for some reason you want two loops which is normally not needed.
 
Upvote 0

nick1408

Board Regular
Joined
Jan 18, 2010
Messages
80
Well the ultimate goal is to have all location A1 in Rack A listed underneath the heading A1, then the same for A2 and so on
 
Upvote 0

Forum statistics

Threads
1,190,958
Messages
5,983,843
Members
439,866
Latest member
jh3268

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
Top