Assign values to cells

ChristineJ

Well-known Member
Joined
May 18, 2009
Messages
761
Office Version
  1. 365
Platform
  1. Windows
Column N has numerical values, such as N1 is 10, N2 is 15, etc. Column O has text values that are cell references, such as O1 is B7, O2 is B9, etc.

The number of rows may vary, but for every value in column N there will be a corresponding cell reference in column O.

Is there VBA code that can assign the value in column N to the cell referenced in column O? Thanks.
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
You can do this without VBA. Put his formula in cell N1 and copy it down: =INDIRECT(O1)
 
Upvote 0
My take on this
VBA Code:
Sub ChristineJ()
   Dim Cl As Range
   
   For Each Cl In Range("O1", Range("O" & Rows.Count).End(xlUp))
      If Not Cl.Value = "" Then Range(Cl.Value) = Cl.Offset(, -1).Value
   Next Cl
End Sub
 
Upvote 0
Fluff - Yes, this is what I am looking for. However, it failed at "Range(Cl.Value) = Cl.Offset(, 1).Value". The message was Method 'Range' of 'Object _Global' Failed.

Thanks so much for the help.
 
Upvote 0
What was the value of Cl.Value when it fails?
 
Upvote 0
Completely my fault. There were table headings in cells N1 and O1.

I deleted the table and just put 66 in N1, B7 in O1, 55 in N2, and B9 in O2. It is not generating an error any more, but it is not placing the 66 and 55 in cells B7 and B9, respectively.

Is it possible to leave the table headings and start the code in row 2?

Thanks!
 
Upvote 0
To ignore the header use
VBA Code:
Sub ChristineJ()
   Dim Cl As Range
   
   For Each Cl In Range("O2", Range("O" & Rows.Count).End(xlUp))
      If Not Cl.Value = "" Then Range(Cl.Value) = Cl.Offset(, -1).Value
   Next Cl
End Sub
Not sure why it was not copying the values
This is what I get
+Fluff New.xlsm
DEFGHIJKLMNO
1
2101D10
3abcH5
4123G11
5abc
6
7
8
9
10101
11123
Sheet2
 
Upvote 0
Works PERFECTLY now! Awesome. Thanks for sticking with me on this!
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,219
Messages
6,123,687
Members
449,117
Latest member
Aaagu

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