VBA Loop to paste a different value into blank cells on different worksheet

smanni3

New Member
Joined
Dec 9, 2021
Messages
3
Office Version
  1. 365
Platform
  1. Windows
I have two worksheets in the same workbook, Sheet 1 which has % by date and Sheet 2 which I overwrite each month with the new %.
Sheet 1 Looks like this, I want to copy each instance of Location A and paste it into the next blank cell in Sheet 2. So that I copy Container 1 - Location A and paste into D13 which is blank and then copy Container 2 - Location A and paste it into the next BLANK cell in Sheet 2 which is D24 and corresponds to Nov-21 of Container 2. I want to repeat this until the last cell in the Range on Sheet 2 because I don't want to continue the process for EVERY blank just the Blanks in the current populated range. Any help with this is greatly appreciated!
1639058257654.png
1639058345468.png
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Hi and welcome to MrExcel.

Unfortunately in your images the letters of the columns are not visible.
So I'm going to assume that the Container column on sheet1 is in column B.
The % column of sheet2 is in column D.

Note: So that this does not happen, you can use the XL2BB tool minisheet, which allows you to paste information from your sheet, for example:
Dante Amor
ABCD
1ContainerLocationPercent
21A45%
31B68%
41C28%
51D14%
61E88%
71F91%
82A69%
92B16%
102C71%
112D85%
122E15%
132F46%
143A79%
153B85%
163C15%
173D46%
183E73%
193F35%
204A36%
214B17%
224C58%
234D85%
244E46%
254F14%
265A78%
Sheet1


Try this:
VBA Code:
Sub LoopValues()
  Dim c As Range, f As Range
  
  For Each c In Sheets("Sheet2").Range("D2:D" & Sheets("Sheet2").Range("C" & Rows.count).End(3).Row).SpecialCells(xlCellTypeBlanks).Areas
    Set f = Sheets("Sheet1").Range("B:B").Find(c.Offset(, -2).Value, , xlValues, xlWhole, , , False)
    If Not f Is Nothing Then c.Value = f.Offset(, 2).Value
  Next
End Sub
 
Upvote 0
Sheet 1 has my Percent Met by Category, Measure and Location. I want to copy the Percent Met for Location A ONLY and paste it into Sheet 2 for each Measure.
For example, I want to copy E3 from Sheet 1 and paste into the first blank cell in Sheet 2 (D13). It has to look for the Blank Cell because I already have code that creates that blank cell and it changes each month. So my second one would be to copy E9 where Category, Measure are same in both sheets and Location = A. Paste that value in Sheet 2 for same Category and Measure in cell D26. Continue to Copy Cell E15 from Sheet 1 where Category and Measure match sheet 2 then paste in cell D38. Can someone help me? This seems to be beyond my expertise. I need to repeat this process until there are no more blanks in Sheet 2 and no more Location A in Sheet 1.
1641325945752.png

1641325995382.png
 
Upvote 0
Hi and welcome to MrExcel.

Unfortunately in your images the letters of the columns are not visible.
So I'm going to assume that the Container column on sheet1 is in column B.
The % column of sheet2 is in column D.

Note: So that this does not happen, you can use the XL2BB tool minisheet, which allows you to paste information from your sheet, for example:
Dante Amor
ABCD
1ContainerLocationPercent
21A45%
31B68%
41C28%
51D14%
61E88%
71F91%
82A69%
92B16%
102C71%
112D85%
122E15%
132F46%
143A79%
153B85%
163C15%
173D46%
183E73%
193F35%
204A36%
214B17%
224C58%
234D85%
244E46%
254F14%
265A78%
Sheet1


Try this:
VBA Code:
Sub LoopValues()
  Dim c As Range, f As Range
 
  For Each c In Sheets("Sheet2").Range("D2:D" & Sheets("Sheet2").Range("C" & Rows.count).End(3).Row).SpecialCells(xlCellTypeBlanks).Areas
    Set f = Sheets("Sheet1").Range("B:B").Find(c.Offset(, -2).Value, , xlValues, xlWhole, , , False)
    If Not f Is Nothing Then c.Value = f.Offset(, 2).Value
  Next
End Sub
Sheet 1 has my Percent Met by Category, Measure and Location. I want to copy the Percent Met for Location A ONLY and paste it into Sheet 2 for each Measure.
For example, I want to copy E3 from Sheet 1 and paste into the first blank cell in Sheet 2 (D13). It has to look for the Blank Cell because I already have code that creates that blank cell and it changes each month. So my second one would be to copy E9 where Category, Measure are same in both sheets and Location = A. Paste that value in Sheet 2 for same Category and Measure in cell D26. Continue to Copy Cell E15 from Sheet 1 where Category and Measure match sheet 2 then paste in cell D38. Can someone help me? This seems to be beyond my expertise. I need to repeat this process until there are no more blanks in Sheet 2 and no more Location A in Sheet 1.
1641325945752.png

1641325995382.png
 
Upvote 0

Forum statistics

Threads
1,215,741
Messages
6,126,587
Members
449,319
Latest member
iaincmac

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